NodeJs – Get Started

Download NodeJs:

You have to install the NodeJs with instructions from below sites

Node.js official web site:

Node.js on github:

Node.js community conference

Install the Long term Support – v6.10.0 LTS

Select Your Bit Architecture 32 or 64

Run The Downloaded File

Complete The Setup By Finish

Getting Started with NodeJs :
Once you have installed a nodeJs in your computer check it by entering this cmd line in your Command Prompt.
node -v
This will tell you the version of the node js you have installed .

Create a server and say “hello world” in your browser :

You can use any IDE or any text editor tool that supports the javascript syntax .
However, an IDE that supports auto complete features for Node.js API is recommended e.g. Visual Studio, Sublime text, Eclipse, Aptana etc.

Paste the below codes in any text editor.

var http = require('http');
 http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/html'});
   res.end('Hello World!');

Save the file in your local drive in the name of server.js. you can name anything but ends with .js extension .
Create a Folder (node project) D drive and store the file inside folder.
For example D:\node project\server.js

The code tells the computer to write a “hello world” if the user trying access your computer port on 5050.

Run the server:

Starting the server file in nodeJs pretty simple . open the command prompt and Navigate your file directory where the file exist .
Initiate server.js file by doing this.
cd D:\node project
Run a file:
node server.js
The file will started serve you on respected port .

If you are a windows user starting the server for first time will ask you for access permission.Click “Allow access” Button.

If anyone tries access the port 5050 it will return the message “hello world” to the browser.
Start your internet browser, and type in the address: http://localhost:5050

Node Js server is same as Http apache Server But the difference is Node based server process the request much faster than a traditional server.Node server is asynchronous ,single threaded and having a capability to serve large number of request compare with traditional servers.

Next Chapter >> Modules

Leave a Reply

Your email address will not be published. Required fields are marked *