How To Install Nodejs
How To Install Nodejs
04
(Trusty Tahr)
In this article we are going to have look into the installation and basic usage of node.js
application. Node is a set of libraries for JavaScript which allows it to be used outside of
the browser. It is primarily focused on creating simple, easy to build network clients and
servers.
Insatallation.
You will have to download the package from the official site here. After the download
type the following commands in the terminal.
tar -xzf node-v0.x.x.tar.gz
cd node-v0.x.x.tar.gz
./configure
sudo make install
The above commands should do the installations now lets go for the dependencies
required.
The above commands are just to verify that your nodejs is installed properly. For futher
information about the iinstallation click here.
First Program.
Its time that we start with the basic famous program "Hello World!." Just copy this code
into any text editor and save it as "your-name.js".
console.log('Hello World!.');
And save it as "http.js". Now goto the terminal and type in:
node http.js
The first thing you'll notice is that this program, unlike our first one, doesn't exit right
away. That's because a node program will always run until it's certain that no further
events are possible. In this case the open http server is the source of events that will
keep things going. Testing the server is as simple as opening a new browser tab, and
navigating to the following url: http://localhost:8080/. As expected, you should see a
response that reads: 'Hello Http'.
You can also check that by opening a new terminal window and typing: