Skip to content

Instantly share code, notes, and snippets.

@dileephell
Created October 25, 2012 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dileephell/3951807 to your computer and use it in GitHub Desktop.
Save dileephell/3951807 to your computer and use it in GitHub Desktop.
var http = require('http');
http.createServer(function (req, res) {
// set up some routes
switch(req.url) {
case '/':
// show the user a simple form
console.log("[200] " + req.method + " to " + req.url);
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.write('<html><head><title>Hello Noder!</title></head><body>');
res.write('<h1>Welcome Noder, who are you?</h1>');
res.write('<form enctype="application/x-www-form-urlencoded" action="/formhan$
res.write('Name: <input type="text" name="username" value="" /><br />');
res.write('Age: <input type="text" name="userage" value="" /><br />');
res.write('<input type="submit" />');
res.write('</form></body></html');
res.end();
case '/formhandler':
if (req.method == 'POST') {
console.log("[200] " + req.method + " to " + req.url);
req.on('data', function(chunk) {
console.log("Received body data:");
console.log(chunk.toString());
});
}
}
}).listen(8098);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment