articles

Home / DeveloperSection / Articles / Hello World in Node.js

Hello World in Node.js

Anchal Kesharwani6402 18-Aug-2014

In this article, we describe the example of hello world in node.js.If you want to learn how to install and setup node.js first, then you can read my previous article using below link:

http://www.mindstick.com/Articles/6936b641-b351-481c-900c-7741a5b42fd7/Install%20and%20Setup%20Node%20js

We open the command prompt with administrator and change the location where you want to keep your js file as like this:

C:\node;

Hello World in Node.js 


Let we go to create a simple program for Hello world in node.js. Here, where we want to store our file we create a test.js file and select through command prompt but here we select c:\node folder and code into test.js file:

var http = require('http');

http.createServer(function (req, res) {

    res.writeHead(200, {'Content-Type': 'text/plain'});

    res.end('Hello World\n');

}).listen(1337, "127.0.0.1");

console.log('Server running at http://127.0.0.1:1337/'); 

To run this program command prompt type the node filename.js

Hello World in Node.js

And run on the browser:

Hello World in Node.js

The output of the test.js file by node.js. I hope that this article is helpful for you.

 


Updated 07-Sep-2019

Leave Comment

Comments

Liked By