Nodejs HelloWorld Example

This tutorial is the quick guide to show you how to write the classic “Hello World!!!” example in Nodejs. This example is using the 0.8.x version of Nodejs installed on Windows 7.

  1. Install Nodejs

    Refer this article for installing Node.js on Windows. This installation very easy and it starts with downloading the executable on windows and installing it.

  2. Hello World Example in Nodejs

    Below code shows you nodejs hello world example

/* Welcome to Kodehelp Programming example for Nodejs.
 * Below example show you how to create Hello World Program in Nodejs.

 var http = require('http'); // This statement is to include the http module in this Program
 http.createServer(function (request, response) {
 	response.writeHead(200); // This is status code in http header
 	response.write("Hello World !!!\n"); // Classic Hello World Statement
 	response.write("\t Welcome to Kodehelp Nodejs learning."); // Additional text from Kodehelp
 	response.end();// Close the connection
 }).listen(3000); // Listen for connection on this port. You can use any port number.

 console.log('Listening to port 3000'); // console statements
 console.log('Go to URL http://localhost:3000 or');

To run this example goto command prompt and navigate to the path where this example file is located, and execute command node HelloWorld.js. Now go to browser and type http://localhost:3000.

Please Post Your Comments & Reviews

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.