How do i set a variable in app.js and have it be available in all the routes, atleast in the index.js file located in routes. using the express fra
I used app.all
The app.all() method is useful for mapping “global” logic for specific path prefixes or arbitrary matches.
In my case, I'm using confit for configuration management,
app.all('*', function (req, res, next) {
confit(basedir).create(function (err, config) {
if (err) {
throw new Error('Failed to load configuration ', err);
}
app.set('config', config);
next();
});
});
In routes, you simply do req.app.get('config').get('cookie');