Sunday, May 20, 2012

Starting With Node on Windows - Part2

In last post  we start with node on windows and create a simple console based "Hello World" program in node.
But node is designed to serve on HTTP protocol so today we will write our 1st server side node program.

Here is the code
//Load http module required for http protocol communications
var http = require('http');
//Configure http server to respond all request with Hello World From Node Server
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World From Node Server\n");
// Listen on port 8080, IP defaults to
// Put a friendly message on the terminal
console.log("Server running at");

Save above code as server-helloworld.js

Start node server as
>node server-helloworld.js
Server running at
Now go to and see the magic

No comments:

Post a Comment