# HTTP Module in Node.js

Published 2022-12-03

This tutorial explains to you the Node HTTP module and how you can create HTTP servers using this module.

Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP).

In order to create an HTTP server example in Node.js you have to test if Node.js is installed:

If the Node.js is not installed you have to Install Node.js on your machine.

After that you have to write the code. For my example I created the following simple HTTP web server in Node.js:

var http = require("http");
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 as "Hello World"
   response.write('Hello World !\n');
   response.write('This is my first HTTP Server in Node.js');
// The Command Line will print the message
// When/ where you run the HelloWorldNodeJs.js file
console.log('Server running at http://localhost:8084/');

Save the code in a file named "HTTPServerNode.js" and run it :

ou can see that you can log some information on the console as well.

When you open your browser at http://localhost:8084 you will see: