support@codebucket.net

How to run Hello World in Node Server

How to run Hello World in Node Server

K. M. Shawkat Zamil | September 18, 2022

Hello Developers,

In this tutorial, I will show you an easy way to run Hello World on the Node server.

To run anything in the Node server first we need to download Node on our local computer from the link below:

 

Node.Js Download Link: www.nodejs.org/en/

 

After downloading and installing it we have to follow some steps:

  • First, we need to create a js file. I have created as main.js
  • Connect http module in the http variable
  • Call createServer() method
  • Write an anonymous callback function. This function has two parameters request and response in the server variable
  • Call listen() method in a port

 

var http = require('http');

var server = http.createServer(function(request, response){
    response.end('Hello World');
});

server.listen('5050');

console.log('Server Running Successfully');

 

Then run the below command in the terminal to execute the file.

 

node main.js

 

We will find "Server Running Successfully" in the terminal. Hit the below line in the browser:

 

http://localhost:5050

 

This might help you in the journey of development.

 

Read More: How to work with Request and Response in NodeJs

 

K. M. Shawkat Zamil

K. M. Shawkat Zamil

Senior Software Engineer

I am a Senior Software Engineer in a reputed company in Bangladesh. I am a big fan of Laravel, PHP Programming, MSSQL Server, MySql, JavaScript, and lots more. I love to help people who are especially eager to learn. I believe in patience and motivation.