Friday, January 6, 2012

Create Server with Node js

We can create a full fledged SERVER in Node.js , we need HTTP server to handle all web requests and responses  and to serve web pages.

lets make a simple server,At first it seems like tough task to create server , but with node js its not 

  

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);

That's it! You just wrote a working HTTP server. Let's prove it by running and testing it. First, execute your script with Node.js
require HTTP  its like include header files in c/c++.  it include the module called "http". Now In  http.createServer passing anonymous function (function with no name).  


No comments:

Post a Comment