How to use node.js?

Introduction:

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, "127.0.0.1");

console.log('Server running at http://127.0.0.1:1337/');
 
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:http://nodejs.org/ 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:  http://127.0.0.1:1337/

You should see familiar Hello World message.

References:
node.js Download: http://nodejs.org/
node.js Hello World Example: http://www.theprojectspot.com/tutorial-post/Node-js-for-beginners-part-1-hello-world/2
More detailed discussion: http://net.tutsplus.com/tutorials/javascript-ajax/this-time-youll-learn-node-js/

Comments

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?