Getting started with node.js on Linux
In this tutorial i will walk you through the installation of node.js on your Linux system and executing your first script with node. To get started goto the official node.js website and download the Linux Binaries file (as shown in the screenshot below) according the bit version of your system.
Save the downloaded file in a specific directory and open Terminal, now execute the following command to extract the contents of the file which must be having the .tar.gz extension.
sudo tar -zxvf node-v0.8.18.tar.gz
Once the file has been extracted you will see that a new directory has been created with the name node-v0.8.14-linux-x64. We are halfway in setting up node, now we need to export the environment variable for the node’s /bin directory so that we can access its console from anywhere. To do so, goto your home directory and open .bashrc file and scroll till the end. If you have java installed on your system then you will probably be having a environment variable already set for it, now you just need to add the path for node below it as shown in the screenshot below.
Now your done with the node.js setup. Type node in your console and it should put you in the node console.
Executing first script with node.js:
In the second part of this tutorial we will create a simple file with one line that will print Hello World when executed with node. Firstly create a file named firstDemo.js with a single line given below:
[js]console.log("Hello World");[/js]
Now goto terminal and type the command shown in the screenshot to execute the firstDemo.js file, be sure that you are in the directory where you create the file.
Hope it helps 🙂