Installing Node.js and Express.js in Mac

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.

To clarify that node is installed open terminal and type node and press enter.screen-shot-2016-11-01-at-2-32-18-pm

You will see ‘>’ mark waiting for the commands as in the above image. Try logging the usual “Hello World!” in the terminal.
screen-shot-2016-11-01-at-2-35-39-pm
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.

Express.js

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.

Do not worry if it shows some errors or debugs.
Verify the installation by executing

if its installed properly then you will see this,
screen-shot-2016-11-01-at-2-42-13-pm

Unfortunately, I faced a problem while installing Express,
When I executed the $ express -h command, i got

If you’re also facing the same problem, do not panic I have found the solution. Run the generator command with sudo

the terminal will expect the password to proceed, once the installation is a success you will see

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.

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

If the app is running successfully you will see the below message in the terminal

To verify,
Open any browser and traverse to

http://localhost:3000/

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.

Output

screen-shot-2016-10-29-at-10-43-01-am

You will need:-To stop the application, just do Ctrl+c on terminal.

Happy Coding……:)