How to use node.js?


Node.js is a platform built on Chrome's JavaScript run-time for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js is a server-side version of JavaScript. That means all the things all them cool things about JavaScript apply here.

What makes Node any different from the rest?
Node is evented I/O for V8 JavaScript. V8 is Google’s super fast JavaScript implementation that’s used in their Chrome browser. JavaScript’s ability to pass around closures makes event-based programming dead simple.

Node is not strictly for web development. You can think of Node as a framework for server development of any kind. With Node you can build an IRC server, a chat server, or HTTP server as done in following hello world example. 

You can use node.js to create light weight web server. See the following example from node.js tutorial site:

var http = require('http');
  http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.write("Dynamic contents...");
      res.end('Hello World\n');
  }).listen(1337, "");

console.log('Server running at');
Above code is java script so you can write your dynamic code generation logic in java script and start using it in no time.

You will have to download and setup node.js from link: for Windows or whatever platform you prefer to use.

Start the web server using command:
node hello.js

To test if above sample works open your browser and hit url:

You should see familiar Hello World message.

node.js Download:
node.js Hello World Example:
More detailed discussion:


Popular posts from this blog

How do I optimize GWT compiler for faster compilation?

How to enable internet access from Android emulator using proxy?

How to use Fork/Join Framework's RecursiveAction feature in JDK7?