Getting Started Nodejs With Example

Hello Getting Started Nodejs With Example : In this tutorial we will learn how to install nodejs and create node project and run by command line on console or localhost.

Step 1 :- First you need to download nodejs set-up from here you can get all OS compatible nodejs setup. just download it and install setup in your system.

Step 2 :- when you done with installation process, then you have to start command prompt and go to the current directory where you installed nodejs and check nodejs version with following command :

C: \Program Files\nodejs>node -v


If you will get v4.1.0 or v(any version) on your cmd means you successfully installed nodejs.

After that you have to check npm [ node package manager ] version using command line below command.

C: \Program Files\nodejs> npm -v


If you will get version means you successfully installed nodejs set up with npm.

Now you can create hello.js file and check and run that file with following command with following code.

create one file in our installed node directory with name hello.js and put over their following code :

// Call the console.log function.
console.log("Hello World");

and again go to the command line and run following command :

C: \Program Files\nodejs>node hello.js

Hello World

If you will get result Hello World so you run your first nodejs code from command line.

Now you need to check your hello.js file output on your browser so that you have to follow following code:

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World\n');

console.log('Server started');

Again run from command prompt with :

C: \Program Files\nodejs>node hello.js

Server Started

Then go to your browser and type http://localhost:8080/ and go. You will get result on your browser

Hello World

hello-world nodejs
hello-world nodejs

I think you understand the basic need of nodejs.