Tuesday, June 10, 2014

"Hello World", http server using Node.js

A simplest http server implemented using Node.js.


Create file node server.js.
var http = require("http");

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

Run

$ node server.js


Then visit http://localhost:8888/ in browser to load "Hello World".

No comments:

Post a Comment