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:

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


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, "");

console.log('Server running at'); 

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.


  Modified On Nov-30-2017 05:24:47 AM

Leave Comment