Node.js for beginners 1 - Setting up

Thursday, November 19, 2015

Let's forget about all the background details for now. What you need to know is that Node.js is based on JavaScript and mainly targets at writing server side code with JavaScript. That's it. Let's start writing our first Node.js application.

Step 1 - Setting up the local environment.

You need two basic things to do this.
    a. A text editor
    b. Node.js binary installables (Don't worry, I'll explain)

Installing on linux environment

Execute the following commands on the terminal to extract the required files on your computer.

$ cd /tmp
$ wget http://nodejs.org/dist/v0.12.0/node-v0.12.0-linux-x64.tar.gz
$ tar xvfz node-v0.12.0-linux-x64.tar.gz
$ mkdir -p /usr/local/nodejs
$ mv node-v0.12.0-linux-x64/* /usr/local/nodejs

and then add the url to the PATH environment variable.

export PATH=$PATH:/usr/local/nodejs/bin

Installation on windows

Installation on windows is pretty easy. Just run the installation msi and you are done!

Step 2 - Verifying the installation

Create a JavaScript file, with the name verify.js on your computer with the following content in it. (you can use any name for the file. Just make sure to use the same name in the next step also)

console.log('Welcome! Node.js is installed properly');

Then navigate to the directory from the terminal and execute the following command.

$ node verify.js

If Node.js is installed properly, you will see our welcome message on your terminal. Now you can go ahead with our next tutorial

Link




4 comments:

  1. Wow! I am really new to node.js and I followed this. It really helped me. This is a very interesting tutorial guide. Keep it up.

    ReplyDelete
    Replies
    1. I would like to share something that I came across with. I went troubleshooting when installing node.js with its installer. It gave me the following message.
      "There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor".
      I resolved it by going to Properties -> Security on the C:\Users\Username\AppData\Local\Temp folder and giving 'Everyone' the 'Full control' permission. Then the installer that previously failed worked successfully.

      Delete
  2. Well described!!! Very helpful to beginners like us! Thanks and carry on the good work (Y)

    ReplyDelete
  3. If you are using Ubuntu 13.04 or a higher version, executing the following commands to install Node.js would be more easy.This will install Node.js and npm.
    $ sudo apt-get install npm
    $ sudo ln -s /usr/bin/nodejs /usr/bin/node

    ReplyDelete