About a week ago I was wondering how to access my app settings from inside a module of my routes or some route middleware, and didn’t find the response on that moment.
Today, while I was debuging some parameters on my request the answer appeared on my eyes: both, request and response objects contain a reference to the express app
On my app.js :
//... Some cool lines above ...
var awsm = require('./awsm');
app.set('cool developer', 'erick');
// ... More cool lines ...
app.get('/awesome/:code', awsm.awesome);
// ... Final cool lines ...
And then on my awsm.js
//... Some cool lines above ...
exports.awesome = function(req, res) {
console.log('app on req', req.app.set('cool developer'));
console.log('and also on res', res.app.set('cool developer'));
// ... More cool lines ...
}
// ... Final cool lines ...
And finally, after executing the app and accessing my route, I get on my console:
app on req erick and also on res erick
One useful value that is already inside settings is “env” with the current environment where the app is running.
Happy settings!
Node.js