Organize routes in Node.js
Posted
by
NilColor
on Stack Overflow
See other posts from Stack Overflow
or by NilColor
Published on 2011-01-05T08:50:31Z
Indexed on
2011/01/05
8:53 UTC
Read the original article
Hit count: 170
node.js
|url-routing
Hello!
I start to look at Node.js. Aslo I'm using Express.
And I have a question - how can I organize web application routes? All examples just put all this app.get/post/put()
handlers in app.js and it works just fine. This is good but if I have something more than simple HW Blog? Is it possible to do something like this:
var app = express.createServer();
app.get( '/module-a/*', require('./module-a').urls );
app.get( '/module-b/*', require('./module-b').urls );
and
// file: module-a.js
urls.get('/:id', function(req, res){...}); // <- assuming this is handler for /module-a/1
In other words - I'd like something like Django's URLConf but in Node.js.
© Stack Overflow or respective owner