In an earlier post on Node.js, you saw how it can really improve the productivity by using it’s standalone JavaScript runtime to execute the scripts. The Node.js home page provides a six liner example of creating a simple Web server that can process HTTP requests, using it’s API. The piece of code is shown below.
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
Execute this script and you have a web server up and running in few seconds.
This ready made, extremely light-weight web server has been very useful while developing and testing mobile applications. Number of times, you have to communicate with the server and exchange data, from a mobile device or an Android/iOS device simulator. Setting up a server like tomcat/IIS just for this purpose has been really painful and a tedious process.
Node.js has made this job, easy. Creating a web server, tweaking it to behave the way you want, make it deliver the response that your application needs, all these have become very agile.
I have started using this Node.js server for playing with new stuff and it has made learning more enjoyable as you can get to the point faster than before.