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');
        }).listen(8125);
    console.log('Server running at http://127.0.0.1:3000/');
    
  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 http://127.0.0.1:3000
  6. Open a browser and put http://127.0.0.1:3000/ in the address bar.
    You should see it say:

    Hello World!