In this tutorial, We are going to learn how to create a simple Hello World Node Js Application. We already have a basic information of Node.JS from our previous session. In this session, we will see how can we create a simple Hello World Node.JS Application.

Introduction:

Before getting started with Hello World Node.Js application we need to know about few major component related to a basic Node.JS application.

1- require directive – require directive is used to include required Node.JS module.

2-Create Server – The next thing we need to do is to create a server that will listen to the incoming request from the client.

3-Process Request and Returned Response – After the server is created in the previous step, this server is used to process incoming request from the server and returned the response.

Creating Hello World Node.JS Application:

Step 1- Create a folder in your System Drive with the Name NodeJSDemo (or any name you want).

Step 2- Create a JavaScript file called HelloWorld.js in NodeJSDemo directory. Write the file code in HelloWorld.js file.

//require directive
var http = require("http");
//create Server
http.createServer(function (request, response) {

// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
 
// Send the response body
response.end('Debug On Web Hello World Node.JS Application\n');
}).listen(8080);

Step 3- Open Node.JS command prompt.

Step 4- Navigate to the directory location and start the server using the below command.

Node HelloWorld.Js

Hello World Node.JS

Where HelloWorld.js is your file name.

Step 5- Now open your browser and hit the following URL.

http://localhost:8080/

You will get a response something like that.

Hello World Node.js

This is the output what we have returned from Create Server.

View More:

Conclusion:

Hope this tutorial will help you in learning Node.Js as a beginner. I will be happy to receive your feedback, comments and suggestions.

Thank You.

Leave a Comment