Express req.app Property
What you’ll learn
- What
req.appreferences in Express request flow. - How to read app settings inside middleware/handlers.
- How to share app-level helpers safely.
- How to avoid overcoupling handlers to global app state.
Usage syntax
javascript
req.app
req.app.get(settingName)1
Read app setting from request
javascript
app.set('siteName', 'CodeToFun');
app.get('/info', function (req, res) {
res.json({ site: req.app.get('siteName') });
});2
Use req.app inside middleware
javascript
app.set('requestSource', 'api');
app.use(function (req, res, next) {
req.source = req.app.get('requestSource');
next();
});❓ FAQ
It is a reference to the current Express application object handling the request.
Use it when middleware or handlers need application-level settings or shared app-level values.
Yes. For example, req.app.get('settingName') reads values set with app.set().
Yes, in normal Express request flow it is available on the request object.
Prefer config and shared service references; avoid mutable request-specific state in app object.
Did you know?
req.app gives access to the current Express application instance from inside middleware and route handlers.
4 people found this page helpful
