req.app
This property holds a reference to the instance of the Express application that is using the middleware.
If you follow the pattern in which you create a module that just exports a middleware function and require()
it in your main file, then the middleware can access the Express instance via req.app
For example:
1 2 | //index.js app.get( '/viewdirectory' , require( './mymiddleware.js' )) |
1 2 3 4 | //mymiddleware.js module.exports = function (req, res) { res.send( 'The views directory is ' + req.app.get( 'views' )); }); |
Please login to continue.