How to write first application in Node.js ?

  1. Download an OS-appropriate node.js
  2. Now, create a new file in the same folder as your node.exe and rename that to firstScript.js.
  3. Put this Javascript in that file:
        var http = require('http');
        http.createServer(function (request, response) {
            console.log('request starting...');
            response.writeHead(200, { 'Content-Type': 'text/html' });
            var html = '<p>Hello World!</p>';
            response.end(html, 'utf-8');
    console.log('Server running at');
  4. Open a cmd.exe and cd c:\path\to\the\node\executable, where node.exe resides.

    node firstScript.js
  5. You should see it say:
    Server running at
  6. Open a browser and put in the address bar.
    You should see it say:

    Hello World!