Node.js in Action: Setup ExpressJS and Run Node Server

Introduction 

This is the "Node.js in action" article series. This article explains node.js and various components associated with it. In our previous article we covered many topics, you may read them here.

In this article we will cover a very important topic of node.js. We will learn how to install and run Express.js on top of node.js. The truth be told, if this is the first time you are hearing the name Express.js then only this article may not help you to understand the concept of Express.js. That was true for me, I had referred to many blogs and posts to understand it. So, don't be depressed and discouraged, we will learn Express.js and definitely.

 

Let's explain about Express.js at first. Many people think that node.js is a framework, but it's not. It's a software development platform. It allows us to write JavaScript code to build server-side applications. So, node.js is not a framework but Express.js is a framework and if we say simple framework we might not be appropriate.

It's better to say, a very very (and a few times more, haha..) popular framework to develop applications on top of node. The framework will do half of our job when we create one new node.js application using Express. So in a broad sense we can say it's something like Ruby On Rails, where Ruby is a programming language and Rails is a framework

How to use express.js? As we said, Express.js is a framework and it's available in the Nugget Package Manager.

Install express.js globally

The advantage of global installation is that, from anywhere we can call express.js frameworks to create a node.js application stricture for us. To install express in a global position, open a command prompt and pass the following command.

Install Express

Now, once It's successfully installed in the system, we are allowed to use express. Now, after explaining that, Express will create an entire node.js skeleton for us, we will see it practically. Write the following comment in the command prompt.

Express TestNode

The command is “express <foldername>”. We are now seeing that the solution was created successfully using express.js. If we browse the app location then we will see the following screen.

Expanding TestNode

There are a few folders and one .js file and one JSON file will be created. The folders and files have certain purposes and meanings, we will explain them in a future article.

Install npm in application

This is the next step. In this step we will install npm in the same application. Go to within the application and write the following command.

npm Install

If you are lucky enough , you will see that npm was successfully installed in this application.

Cheers! Now run your node server.

Yes, we are done and it's time to up our node.js server. I am running the server that we just created.

Executing Node App

Access node.js server

Open a browser window and call localhost by specifying the port.

Running by Localhost

Now, the question may come to your mind, how does the output come? From where does it come? To learn everything, just continue with us. Thanks and happy learning.


Similar Articles