Create HTTP Server in Node JS

In this example, We will show simple program about, Hows to create http server in node js. This example has been tested and shared in the same post.

Example Program

var http = require("http");
var server = http.createServer(function(req, res) {
res.writeHead(200, {"Content-Type": "text/html"});
res.write("<!DOCTYPE 'html'>");
res.write("<html>");
res.write("<head>");
res.write("<title>Creating Server in Node JS</title>");
res.write("</head>");
res.write("<body>");
res.write("<h1>Hello everyone! welcome to dineshkrish.com</h1>");
res.write("</body>");
res.write("</html>");
res.end();
});
server.listen(8081);
console.log("Application is running at http://localhost:8081");

Run it

How to Create HTTP Server in Node JS

No responses yet

Leave a Reply

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