Skip to content

Instantly share code, notes, and snippets.

@jpalala
Created February 2, 2015 08:55
Show Gist options
  • Save jpalala/ffa53a9b0eeb86a13f15 to your computer and use it in GitHub Desktop.
Save jpalala/ffa53a9b0eeb86a13f15 to your computer and use it in GitHub Desktop.
url-parsing with nodejs
var http = require('http');
var sys = require('sys'),
fs = require('fs'),
http = require('http'),
url = require('url');
http.createServer(function (req, res) {
var url_parts = url.parse(req.url);
sys.puts(url_parts.pathname);
switch(url_parts.pathname) {
case '/':
sys.puts("display root");
break;
case '/create':
sys.puts("display create");
break;
case '/edit':
sys.puts("display edit");
break;
default:
sys.puts("oh dear, 404");
}
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment