Node.js HTTP Module

Node.js HTTP Module

Node.js HTTP Module is built-in module which is used to transfer data over the Hyper Text Transfer Protocol (HTTP).

A require() function is used to include the HTTP module in applicaton.

The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client.

A createServer() method of http module is used to create an HTTP server:

Example : 

const http = require('http');

const port = 5555;

const server = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Welcome to aryatechno tutorials!');
}).listen(8080);

server.listen(port function() {

    console.log(`Server running at port ${port}: http://127.0.0.1:${port}`)

})

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

82870