I'm considering using Express framework in my next node.js project. However, a stumbling block for me is non-existence of URL generation for routes like in most other non-Sinatra based frameworks, examples- Django, Flask, Rails etc.
I tried looking for some Connect middleware to serve my task and I did find Barista, Escort, Sherpa and the likes but looking at their GitHub pages, all seem dead and in-active. So, I don't want to go for something that's not maintained anymore for obvious reasons.
My main concern here is that the project may get really large and it WILL be a pain to update URLs in every page whenever business and/or aesthetic requirements change.
Is there something that I failed to see in the docs/tests? If not, then how do I extend the routing framework in Express to do URL generation and make this wrapper available in my views as well as controller functions?
UPDATE: (22/3/2012) I found this page: https://github.com/clyfe/tweet_express/wiki/TODO which specified some routers that do URL generation and stumbled upon the escort router which can also interface with express.
Getting the full URL of a Request in Express # Within a route, we can use the req object to get the full URL. The full URL is composed of a few different pieces: the protocol of the current URL. the host of the URL (i.e. the domain name)
To use the router module in our main app file we first require() the route module (wiki. js). We then call use() on the Express application to add the Router to the middleware handling path, specifying a URL path of 'wiki'.
By using app. route() method, we can create chainable route handlers for a route path in Express.
The express. Router() function is used to create a new router object. This function is used when you want to create a new router object in your program to handle requests.
Or stick with express and use the package reversable-router.
Example from the readme:
app.get('/admin/user/:id', 'admin.user.edit', function(req, res, next){
//...
});
//.. and a helper in the view files:
url('admin.user.edit', {id: 2})
You might try Locomotive, which is built on Express.
It does much more than route generation. From the docs: "Locomotive brings additional MVC-based structure, for architecting larger applications, while leveraging the power of Express and Connect middleware."
Locomotive's router generates helpers that are automatically available to controllers and views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With