Install Node.JS

  1. Download node.js from

  2. Unpack anywhere you prefer.

  3. Export path variable.

    3.1 Open .bashrc file to export path variable (I prefer this way! :P)

$ gedit .bashrc

​ 3.2 Add the following lines to the .bashrc file.

    export NODE_HOME="/home/sayef/node-4.5.0"
    export PATH=${NODE_HOME}/bin:$PATH

​ 3.3 Save, exit and source the .bashrc file to come into effect the changes.

 $ source .bashrc

Install NPM (node package manager)

NPM is a command line interface program to manage node.js libraries. We can install some other fantastic and handy libraries to work with nodejs. We can initiate a server, see the changed effects in browser using those npm packages and making lot more funs with this package manager. Following command will install npm.

$ sudo apt-get install npm

We can check our node version and npm version using

$node -v  
$npm -v

Create NodeJS Project

  1. Create a preferred directory. In my case
$ mkdir /home/sayef/Dev/WebProjects/NodeProjects/hello
  1. Go to the directory and initialize npm there-
$ npm init
  1. A lot of stuffs will be showing in the screen. Just hit through down and will be ended up by saying Is this ok? (yes). This will create package.json file for us with preloaded some environment settings in the directory. Lets check it-
$ ls
  1. Now we just want to create some javascript file, which is definite motivation. So create a javascript file named index.js in the same directory and write up some js stuffs inside the file. We can use atom or sublime text, two best text editor in this regard.
console.log("Hi There!");
  1. Introduce this index.js file with node so that we can further command over this js file through node commands and other handy stuffs.
$ node index.js
  1. To get a quick client side setup, we need two basic libraries, budo and watchify. Also if we want to save this two libraries for further dependencies, we just add save-dev option which will update package.json.
$ npm install budo watchify --save-dev
  1. After reloading (if needed) the package.json file we will see something like that end of the file-
"devDependencies": {
 "budo": "^9.2.0",
 "watchify": "^3.7.0"

So next time we will just write npm install and this two packages will be loaded automatically and will not need to specify explicitly using npm commands.

  1. We have a scripts section in the package.json file like following-
"scripts": {
 "start": "beefy index.js 8080 -- -d",
 "test": "grunt nodeunit -v"

This section automates things while loading the project. We can add budo commands so that we can see the changes live in the browser. It will set up the server while we load the project and will be available to watch from browser. Update the scripts section like following-

"scripts": {
 "start": "budo index.js --live"

Make some changes in index.js-

document.write("Hello World!");
  1. After saving the package.json file just go to the terminal and write
$ npm start

And it will start up a little server on port 9966. If we go to browser and hitting localhost:9966 we can see the effects of index.js file changes.

  1. So we are done! We can write some javascript codes and deploy in a little server and see the effects in the browser.