Wednesday, July 8, 2015

Installing NODE.js in LINUX

Hey Guys.

In this blog let us look at the installation procedure of Node.js. I will leave up to you on how you want to explore the same ;)

Node.js®  ( a platform  for building fast and scalable network applications.  It is really lightweight and is awesome at efficiency. These features comes from the architecture itself as it uses events for its various functionality. It is actually bundled with a lot of awesome libraries which will help you handle server tasks in a more easier manner.

The single thread non-blocking architecture also gives you the feasibility to design for the “First come, first served” which is the key of Nodejs to be more scalable than others.

I was actually not aware of this earlier until i came across a super HTTP tool(htracr) whose pre-requisite was Node which made me inquisitive on what else it can do. I would highly recommend you guys to explore its website for more.

Usually Node.js is included in Ubuntu versions 13.04 and higher.

There are a lot of blogs on the same topic on how to install kinda thing. But recently i was diving into my Mint and i faced a little problems installing it so thought of writing another blog on how it can be done to make it smoother for other guys may be. The best part about linux is , it always come up with one or the other dependencies when you are using the vanilla version which makes one explore more on what is required for what and how does things work. :)

So lets dive in the terminal for a while.

Follow the steps to install Node.js and npm.

$ sudo apt-get install npm
$ sudo ln -s /usr/bin/nodejs /usr/bin/node

If you want to install a more recent version, we have to do it from its PPA. For that first we will require some python libraries. If you already have it, look for an updated one (Suggested)

Following are the steps

$ sudo apt-get install python-software-properties python g++ make

Now lets add a repository to our sources list.We will be using the Chris-lea repository here. There are many others repository but these one seems reliable.

$ sudo add-apt-repository -y ppa:chris-lea/node.js

Next is updating the local repository index which is a necessary step

$ sudo apt-get update

$ sudo apt-get install npm

*I forgot to mention that npm(Node's Packet Manager)

There are some native add-on's from npm which you can install as per your wish

apt-get install --yes build-essential

This should ideally be enough for the running of your first Node program.

Here is a sample for the same:) . Not one of mine though

// First_node.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8007, "");

console.log('Server running at');

To run your program you can type in 

$ node First_node.js

Now, if you navigate to in your browser, you should see the message...

No comments:

Post a Comment