Node fit for http server. To use http module, client must require('http).
To create http server
http.createServer([requestListener]) - it will create a new webserver object.
http.request([port,host]) - refer to the server to connect.
see this simple example
///here we have to include the module, http is a variable, im taking
var http=require("http");
//the request is a read stream which gives data for incoming whereas response object is a write stream // is used to send data to the client.
var server=http.createServer(function(req,res){
// here header we are sending is 200
res.writeHead(200,{'Content-Type': 'text/plain'});
res.end('hello welcome to nodemongo.asia\n');
});
// to run the server on port
server.listen(1337,"localhost");
Node.js offers http module and createServer method returns an object to respond http requests. Object inherits http.Server prototype.
0 comments:
Post a Comment