Installing node.js is very simple and it happens in just some clicks.
Click on the Macintosh installer on the download screen.
Follow the instructions to install Node in your mac, Finally, it prompts to make sure the $path is same as node.js is referring to.
To verify, open terminal and type echo “$PATH”.
Usually, it will be set to the same path, if not or if you changed the folder of installation then add the path to the $PATH variable.
You will see ‘>’ mark waiting for the commands as in the above image. Try logging the usual “Hello World!” in the terminal.
If you see the result as shown then we have reached half way.
Pro tip:- to stop the running node server do Ctrl+c twice.
Now let’s install express.js
When we install node it installs NPM by default, which is used for downloading and maintaining the dependencies and other node modules.
NPM stands for Node Package Manager.
Installing and running express in your application can be done in many ways but I prefer doing it with express-generator since it is very useful in creating application boilerplate or folder structure which makes the app development ease.
Run $ npm install express-generator -g
Do not worry if it shows some errors or debugs.
Verify the installation by executing
$ express -h
Unfortunately, I faced a problem while installing Express,
When I executed the $ express -h command, i got
express :command not found.
If you’re also facing the same problem, do not panic I have found the solution. Run the generator command with sudo
$ sudo npm install express-generator -g
the terminal will expect the password to proceed, once the installation is a success you will see
/usr/local/bin/express -> /usr/local/lib/node_modules/express-generator/bin/express
│ └── firstname.lastname@example.org
│ └── email@example.com
Now you can again verify by executing express -h.
Navigate to the folder where you want your app files to be stored.
Create an App
Create your app structure with express by running
terminal will clearly display the app structure created by the express generator.
create : myapp
create : myapp/package.json
create : myapp/app.js
create : myapp/public
create : myapp/public/images
create : myapp/routes
create : myapp/routes/index.js
create : myapp/routes/users.js
create : myapp/public/stylesheets
create : myapp/public/stylesheets/style.css
create : myapp/views
create : myapp/views/index.jade
create : myapp/views/layout.jade
create : myapp/views/error.jade
create : myapp/bin
create : myapp/bin/www
$ cd myapp && npm install
run the app:
$ DEBUG=myapp:* npm start
It also tells us what needs to be done next, Install the dependencies by traversing to the app folder and executing the npm install command as shown at the end. It will install all the required modules for express.
Run your first express app with the following command
$ DEBUG=myapp:* npm start
If the app is running successfully you will see the below message in the terminal
> firstname.lastname@example.org start /Users/user/WebDevelopment/Node/myapp
> node ./bin/www
myapp:server Listening on port 3000 +0ms
GET / 200 400.862 ms - 170
GET /stylesheets/style.css 200 5.275 ms - 111
GET /favicon.ico 404 34.712 ms - 1295
Open any browser and traverse to
If you see the below image then you have completed the installation and your app is running successfully. Look forward to start coding for your application.
You will need:-To stop the application, just do Ctrl+c on terminal.