node.js as a simple web server

Published: 26 August 2014
on channel: Zariga Tongy
766
5

How to create a simple webserver with node.js
routing with node.js

var http = require('http');

http.createServer(function(request,response)
{
var path = request.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase();

switch(path)
{
case '':
response.writeHead(200,{'Content-Type':'text/plain'});
response.end('Hello World');
break;

case '/about':
response.writeHead(200,{'Content-Type':'text/plain'});
response.end('About');
break;
default :
response.writeHead(404,{'Content-Type':'text/plain'});
response.end('Page Not Found');
break;
}
}

).listen(9999);

console.log("Server Started @ locahost:9999");


On this page of the site you can watch the video online node.js as a simple web server with a duration of hours minute second in good quality, which was uploaded by the user Zariga Tongy 26 August 2014, share the link with friends and acquaintances, this video has already been watched 766 times on youtube and it was liked by 5 viewers. Enjoy your viewing!