Node.js Installation


Getting started :

There are a few things that we require before we can install Node.js. Firstly we need a compiler which can be got by installing the build-essential package. This contains tools (such as the gcc complier, make tool, etc) for compiling/building software from source.

sudo apt-get update
sudo apt-get install build-essential -y


 Some build tools including git :


   sudo apt-get install libssl-dev
   sudo apt-get install git-core


Installing from source :


You will need to download the tar archive of the source code and unpack it into a suitable directory. We will create this directory in /usr/local/src. Note that you will have to use the sudo command in order to write to this directory.

cd /usr/local/src
sudo mkdir node
cd node
sudo wget http://nodejs.org/dist/v0.8.22/node-v0.8.22.tar.gz
sudo tar -xzvf node-v0.8.22.tar.gz


We now need to enter the extracted directory and configure the code. The configure script checks your system to see if the required dependencies are present. Since we have installed these earlier it should report that everything is ok. Note that by default the configure script will ensure that Node.js is installed globally for the whole system. If you wish to install it for use by a single user you can follow the extra instructions here.

cd node-v0.8.22
sudo ./configure
The make command can now be used to compile and install Node.js.

sudo make
sudo make install
This will result in the commands node and npm been installed into the /usr/local/bin directory.

And Remember it is the Stable version for Production Development.

The First Application :



var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('welcome to Node.js World\n');
}).listen(5000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:5000/');

save as server.js


Start the Server :

 node server.js


Test Your Server :

Open Your browser and type the following address  :

http://127.0.0.1:5000/

No comments: