Running a Hello World Server in JavaScript Using Node.js

JavaScript has traditionally always been a client-side language, but Node.js lets you run JavaScript on the server side as well. You know, in case that turns out to be a good idea.

Follow the steps below to run a simple demonstration server using Node.js. Once the server is running, visiting the appropriate page in a web browser will cause the “Hello, World!” message to appear.

1.In a web browser, navigate to “” and click the “Install” button. Download the Node.js installer file to any convenient location.

2. Run the Node.js installer and follow the prompts to install Node.js.

3. In any convenient location, create a new text file named “NodeServerTest.js”, containing the code shown below. Note that this code is only minimally adapted from a sample available at the URL ““.

// This code is minimally adapted from a sample 
// available at "".

var hostAddress = ""; // localhost
var portNumber = 1337;

var http = require('http');

var server = http.createServer
	function (request, result) 
			200, // OK
			{'Content-Type': 'text/plain'}

		result.end('Hello, World!\n');

server.listen(portNumber, hostAddress);

	"Server running at http://" 
	+ hostAddress + ":" 
	+ portNumber + "/"

4. Open a command prompt. Navigate to the directory containing NodeServerTest.js and execute the command “node NodeServerTest.js”. The text “Server running at “” will appear in the command window. (If this command fails, make sure that correct directory for Node.js is present in the “Path” environment variable and try again.)

5. Open a web browser and navigate to the URL ““. The text “Hello, World!” should appear in the browser window.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s