Node.js HTTP module is used to build web server objects that listen to client’s requests similar to Apache HTTP Server. Here are the simple steps for using Node.js HTTP module:
Step 1: Include HTTP module
To include the HTTP module, use the require() method:
```
var http = require(‘http’);
```
Step 2: Create Server
Use the http.createServer() method to create an HTTP server:
```
var http = require(‘http’);
//create a server object:
http.createServer(function (req, res) {
// Write a response to the client
res.write(‘Hello World!’);
//End the response
res.end();
}).listen(8080); //the server object listens on port 8080
```
The function passed into the http.createServer() method, will be executed when someone tries to access the computer on port 8080.
Step 3: Save the file as myfirst.js, and initiate the file:
Go to the command line, enter the following:
```
node myfirst.js
```
Now, your computer works as a server. If anyone tries to access your computer on port 8080, they will get a “Hello World!” message in return.
Step 4: Access the localhost:8080 from your web browser
You can access localhost:8080 from your web browser, it will display “Hello World!”.
The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client. When the server is ready, the callback function is called, in this case informing us that the server is running.