NodeJS + Express

Are you setting up your first NodeJS server?
So lets do that together.

Steps

1. Create a folder and move to that folder. This is the time you could setup a git repository.

To use Express we need to use NodeJS and npm, but we will use yarn to do our package management rather than npm. Once all three are installed we can move to the next step.

2. Let's init the package manager and answer the questions.

yarn init

3. Now we are ready to install express.

yarn add express

4. Create a file app.js and copy the code from here.

At this point your app should look something like this


And node app.js should start a local server and localhost:3000 on your browser should display
Hello World!
Shortcomings:
  • No project structure
  • Not the latest JavaScript standard.
  • It's not Typescript.
  • No testing framework.
  • No hot reloading.
We will solve these in the next blog…

Comments