Skip to content

Instantly share code, notes, and snippets.

@soheilhy
Created January 15, 2013 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soheilhy/4541040 to your computer and use it in GitHub Desktop.
Save soheilhy/4541040 to your computer and use it in GitHub Desktop.
var http = require('http');
var hello = function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Hello! <br />');
res.write('<br />' +
'URL:' + req.url + '<br />' +
'Method:' + req.method + '<br />');
};
var send404 = function(req, res) {
res.writeHead(404, {'Content-Type': 'text/html'});
res.write('Ooops! No resource found at this URL!');
};
http.createServer(function(req, res) {
if (req.url.indexOf('/hello') != -1) {
hello(req, res);
} else {
send404(req, res);
}
res.end();
}).listen(4321, '127.0.0.1');
console.log('Server running at http://127.0.0.1:4321/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment