Setup Express and Run First Application in Node.js

In this article we will take a step-by-step look at setting up Express and creating our first Node.js application.

In this article we will take a step-by-step look at setting up Express and creating our first Node.js application. I assume you have already installed Node. If not then go ahead and install from here

Once node.js is successfully installed, you can install the Express framework by running the npm install express on the command prompt.

install express on command prompt
 
After installing express, I recommend creating a new folder and changing the directory to the newly created folder. I have created a folder expressjs and will create a site named mysite using the express framework. To create the site run the command express mysite. mysite is the name of the site.

run command express
 
 On successful execution of the command above you will get the notifications as below that several files have been created.

 files created
 
 Next to install a dependency. To install that navigate to site director. You can navigate to the site directory using cd mysite. In the mysite directory:

install dependency
 
 It will install all dependencies in the mysite directory.

dependency in mysite directory
 
 After successful installation of the dependency you should get the "npm info ok" message as shown in the figure above. Now you can run the website that was created by express using node.

express using node
 

 In the browser navigate to the server on port 3000 and you will get a basic site created using express up and running.
 
express up and running 
 
This is how you can set up express to create sites running on node.js. In further posts we will look into routing, app.js, routing path and HTTP verbs. I hope you like this.