Skip to content

Instantly share code, notes, and snippets.

@saturngod
Created July 2, 2011 05:32
Show Gist options
  • Save saturngod/1059760 to your computer and use it in GitHub Desktop.
Save saturngod/1059760 to your computer and use it in GitHub Desktop.
Simple routing URL in node.js
var sys = require ('sys'),
url = require('url'),
http = require('http'),
qs = require('querystring');
http.createServer(function (req, res) {
keyword=/\/keyword\/([A-Za-z0-9]+)$/
data=/\/keyword\/([A-Za-z0-9]+)\/data\/([A-Za-z0-9]+)$/;
var url_parts = url.parse(req.url);
var current_url=url_parts.pathname;
if(current_url.match(keyword))
{
result=current_url.match(keyword);
console.log(result);
}
else if(current_url.match(data))
{
result=current_url.match(data);
console.log(result);
}
else
{
console.log(current_url);
}
res.end();
}).listen(1337, "127.0.0.1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment