I have an ExpressJS 3 app and have my routes in a separate file. I'd like to declare some configs in my app.js that are available in the routes file - outside of the route definitions themselves.
In my app.js I would like to do something such as:
app.set('path_to_models', '/path/models/');
Then in my routes/index.js file I would like to be able to do this:
var Product = require(app.get('path_to_models') + 'product');
exports.list = function(req, res){
return Product.find(function (err, products) {
if (!err) {
res.render('product/manage', { products: products });
} else {
res.render('5xx');
}
});
};
I've seen a few posts related to this but none really addressed what I am looking for. I know that I can wrap the routes in a function but would like an alternative way that will keep my code as is if at all possible.