Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

URL Generation for Routes in Express

URL Generation for Routes in Express

Problem

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.

Problem courtesy of: Ishbir

Solution

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.

Solution courtesy of: Luke Vivier

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

URL Generation for Routes in Express

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×