By   July 9, 2016

Using NodeJS and Express for Hosting HTTP Service

In this post we are going to create a simple HTTP service using node and express. The service provides the list of student. It can also provide the details of a student using id as input.

Let’s first start with a simple HTTP service using NodeJS and express.

In order to install express package, we have to define the dependencies in package.json as follows:

Now just running npm install should install all the dependencies (express).

express-install-npm

express-install-npm

Now let’s run the service:

node-app-run

node-app-run

But as we run the service, we get the following:

express-browser-service

express-browser-service

That means we need to add routes to our service. And that’s the reason we have used express module. Let’s change the service as follows to add the required routes:

Now we have the service working. Here are the requests and their responses: