Its quite easy to create a restful web service for testing and during rapid development. Creating a quick prototype or having a contract that certain data format and type are going to expose help application developer and UI developer to work independently.

Here I am going to describe of creating RestFul webservice with NodeJS in 5 min.

Before we go forward, we need some bits.


This process can be perform in any platform. I will be using in Linux(Red Hat).

First get NodeJs binary and extract to a location.


If you want for other platform and OS head to NodeJsdownload Export the path to include the node binary location.

Export PATH=$PATH:node/bin

Create a project directory where you want to create the webservice.


npm install express@3.4.8

I am using older version of express and if you want to use latest version, some syntax might need to tweak as it is in development.


Now create a file myservice.js and copy the following code: or get from github

var express = require('express');
var app = express();


app.get('/movie/getMovie/:name', function(req, res) {
	var name =;
	console.log("Parameter: " + name);

	movie = new Object(); = name;
	movie.genre = "Action";
	movie.rating = "9/10";
	movie.length = "120 min";

	cast = new Object();
	cast.Actor = "Gokul";
	cast.Actress = "Surbala";

	movie.cast = cast;

});'/movie/postMovie', function(req, res) {
	var movie = req.body;
	console.log("Got request: " + JSON.stringify(movie));

app.listen(process.env.PORT || 1337);

The type and content of response can be change according to your need. You can read from a file, propertyfile, db – (go crazy to get from any source)

The url and port can also be change to whatever your need.

Now save the file and startup your web server.

node myservice.js

To Test for GET, you can either use curl or browser to get the result.