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

Adding metadata to express routes

Adding metadata to express routes


Is there any way to add Metadata to the Routes in express? for example:

app.get("/some/route", function(req,res) {
// ...
}, {some: 'meta-data});

I am looking at a sort of AOP approach to my node application so I want to proxy certain routes with authentication and/or logging. To do this I need to be able to assign some sort of hooking identifier to each route to indicate it should be proxied, so the AOP knows nothing about the individual methods and the methods know nothing about the AOP framework...

Then without getting too much off topic I would use something like hooker or some other proxying library to check through all routes where it has some and add a thing interceptor.

So anyway any best practice way to do the sort of thing mentioned above?

Problem courtesy of: Grofit


You almost have it. You can use the bind method to bind variables to a function call.

app.get("/some/route", function(req,res) {
}.bind({test:'hello world'}));
Solution courtesy of: Daniel


View additional discussion.

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

Share the post

Adding metadata to express routes


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription