Created
February 2, 2015 08:55
-
-
Save jpalala/ffa53a9b0eeb86a13f15 to your computer and use it in GitHub Desktop.
url-parsing with nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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