In this post we will show about how to create node.js server with http module.http module includes classes, methods and events to create Node.js http server. Before starting create server in node.js let us to see part of Node.js application. Node.js include three type of module.
- Core Module
- Local Module
- Third party Module
var http = require("http"); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n'); }).listen(8081); console.log('Server running at http://127.0.0.1:8081/');
- var http = require("http") is used to import core module http of node.js for create server.
- http.createServer() is used to create server that listen with port 8081.
Now execute the main.js to start server as bellow