Skip to content

Instantly share code, notes, and snippets.

@khamiltonuk
Created July 14, 2015 06:09
Show Gist options
  • Select an option

  • Save khamiltonuk/60e33eed760b0d59d97c to your computer and use it in GitHub Desktop.

Select an option

Save khamiltonuk/60e33eed760b0d59d97c to your computer and use it in GitHub Desktop.
helloworld.js
var http = require('http');
http.createServer(function(req,res){
// normalize url by removing querystring, optional
var path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase();
switch(path){
case '':
res.writeHead(200, {'Content-type': 'text/plain'});
res.end('Homepage');
break;
case '/about':
res.writeHead(200, {'Content-type': 'text/plain'});
res.end('About ');
}
}).listen(3000);
console.log('server started on localhost:3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment