A developer's Blog Log #2

...Jason Nutt 02/17/2021

Second Blog/ Node.js/ Creating an express.js app

This is the continued walkthrough of Node.js docs...

This blog has morphed and become an express.js study guide.

A re-re-iterated version of compiled notes & learning From Treehouse, YouTube, DevEd, Node.js Docs and more...

Blog # 2:Currently we are learning about the built in file system called fs.

The fs module enables interacting with the file system in a way modeled on standard POSIX functions.

The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems.

In order to use this module, create an app.js file in the root of this directory...

const fs = require('fs');


All file system operations have synchronous, callback, and promise-based forms.

I'm doing all this with the same project that I am writing this blog in. I think that is fine...

...I guess that's fine. We shall see.

The only javascript I have written is that ONE line of code that says

require('ls') , ( require() is a built in function)...

The following concepts are also key to understand asynchronous programming, which is one fundamental part of Node.js:

Asynchronous programming and callbacks

Timers

Promises

Async and Await

Closures

The Event Loop

If anyone needs refreshed on these types of things here are a list of resources that I have used...

Async Await with Guil Hernandez

Asynchronous code in javascript with Treasure Porth

Callback Functions with Andrew Chalkley

Vue.js with Treasure Porth

I will be taking a pause in this blog in order to re-iterate through these videos and re-evaluate the next bit of onfo to blog about...

OK, so, re-routing...We will continue with fs studies later..

Installing express with Andrew Chalkley

The first thing to do when starting a new Node.js project is to install the project's dependencies.

Dependencies are third-party node modules used in your project modules, like express, give you a lot of power, so

you don't have to write a complete Web application from scratch.

to install the applications dependencies on another machine.

Let's take a look at how to start a new Node project, and install Express.

First things first, we're using three primary applications on a local machine, a web browser, a terminal and a text editor

I have my Terminal open in VS Code, I am on a Mac.

...and we are on the internet so we are using a browser.

We'll create all files that we need from scratch as we go.

If you follow along with me, you should have the same results

Now that we know node and npm are running, we can install express

Open the Terminal in VS code. Just like in the first blog type

node -v

then type

npm -v

Now that we are sure that node and our package manager are here and working for us we can go ahead and say

to create a directory that will hold the express application using the command

mkdir flashcards

Let's call the directory flashcards, and open the directory

by using the command cd, and then the directory name, cd flashcards

Now, to initialize a Node application, you can use

npm init -y.

The -y just accepts all the default options... Otherwise, you'd have to type them all by hand.

With our package.json generated, we can install and save Express.

npm install express --save

--save adds this package to the package.json file making it super simple

to install the applications dependencies on another machine.

Now that we have express installed, their should be two .json packages

and some new node modules

Tomorrow we will start to add some code for our application.

That's right! We've just made an express.js application with node modules and everything..

And a good night to all. Tomorrow, we build!

I hope you're excited to build this out