How can I practice setting up express locally?


How can I practice setting up express locally?


As we may remember from the second lesson, express is a node module that we require, which means we need two have at least two things installed in our machine before we proceed:

Node needs to be installed globally
npm needs to be installed globally ( npm install npm -g)

If we have both on our computer then first we make a directory in the location we want our project to be within our files, inside that folder we can create an index.js (or app.js) file and open it in our code editor of preference, some of them like Atom and Visual Studio Code have an integrated terminal window, if ours do not, then we simply need to open our terminal or gitbash window separately.
Once we have the terminal or gitbash window open, we will navigate to the directory using command line (if we need a refresher, here’s a great place to start), for example, in my imaginary file route, my own project is in:


Once there, we will set our node modules in the project directory, as we remember is simply by running through the command line:

npm init

This will also create our package.json file that is where all our packages are being handled through as we install dependencies. Talking about dependencies, express is one of them, so in the same command line, after the last command was executed, we will run:

npm install express

this will create the express library reference and files in our node-modules and now, we can code away in our index.js(or app.js) file we created by requiring express in it as we learned and creating a few routes to some dummy data like the expressions array!

In future lessons, we will learn how to separate routes and use databases so do not worry, because this is just the beginning.