Monday, March 25, 2013

Installing node.js in Linux

I tested these steps in RHEL 5.4 and Ubuntu 12.10.

  1. wget http://nodejs.org/dist/v0.10.1/node-v0.10.1.tar.gz
  2. tar -xvf node-v0.10.1.tar.gz
  3. cd node-v0.10.1
  4. ./configure --prefix=<a directory to which you have write and execute access>
  5. make
  6. make install
  7. Create a file, say Test.js and add the following lines to it
    var http = require('http');

    http.createServer(function (request, response) {
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end('Hello World\n');
    }).listen(8124);

    console.log('Server running at http://127.0.0.1:8124/');
  8. node Test.js
  9. Open a browser and visit http://127.0.0.1:8124/. If all went fine, you should see Hello World in the browser.
It is as simple as that. I did not hit any road block at all. They all went fine.

No comments: