Node.js HTTP Module
In this tutorial, we will learn about Node.js HTTP module and understand how out code working that we have written in Getting started with node.js.
Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the http. To include the HTTP module, use the require() function.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
In this tutorial, we will learn about Node.js HTTP module and understand how out code working that we have written in Getting started with node.js.
Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the http. To include the HTTP module, use the require() function.
var http = require('http');
Node.js as a Web Server
The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client. we used createServer() method to create an HTTP server.
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(3000); //the server object listens on port 3000
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment