Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created June 10, 2010 19:48
Show Gist options
  • Select an option

  • Save toastdriven/433538 to your computer and use it in GitHub Desktop.

Select an option

Save toastdriven/433538 to your computer and use it in GitHub Desktop.
var sys = require('sys');
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
var name = 'World';
if(req.method == 'GET') {
data = require('url').parse(req.url, true);
if(data['query'] && data['query']['name']) {
name = data['query']['name'];
}
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<html><head><title>Hello ' + name + '</title></head><body>Hello, ' + name + '</body></html>\n');
sys.puts('name was: ' + name);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment