Intro to HTTP Server

HTTP server

http is a core module of nodejs. It has createServer method which is asynchronous. It takes a callback function which has a request and response object (typically with any http server).

Example:

var http = require('http'),
port = 1234;

var server = http.createServer(function(request, response) {
    response.writeHeader(200, 
		{"Content-Type": "text/plain"}
	);
    response.write("Hello HTTP!");
    response.end();
});

server.listen(port);

Once we get the request we write header to the response, then write some message and at the end we end it.

Try to see what all things the request object contains.

Just do a console.log(request);

A lot more is there about http module, later you may find a details post about http core module containing its objects, methods and applications in a networking app of Node.js