Express res.app Property

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code Examples

What you’ll learn

  • What res.app is and where it is available.
  • How to read app-level settings from response context.
  • How res.app compares with req.app.
  • How to avoid misusing shared app state.

Syntax

javascript
res.app
res.app.get('trust proxy')
1

Read app setting from response context

javascript
app.set('siteName', 'CodeToFun');
app.get('/info', function (req, res) {
  res.json({ site: res.app.get('siteName') });
});
2

Use app-level shared service

javascript
app.set('logger', console);
app.use(function (req, res, next) {
  var logger = res.app.get('logger');
  logger.log('Request path:', req.path);
  next();
});
3

res.app vs req.app

javascript
app.get('/same-app', function (req, res) {
  res.json({ same: req.app === res.app });
});

⚠️ Common pitfalls

  • Do not store request-specific data in app; use req or res.locals.
  • Avoid mutating app-wide settings inside request handlers.
  • Prefer dependency injection patterns for larger apps instead of scattered app.get() calls.

❓ FAQ

res.app is a reference from the response object to the current Express app instance.
There is no app-instance difference; both properties reference the same app.
Yes, use res.app.get('settingName') for settings created with app.set().
Use it when your code only has response context but needs app-level config/services.
No, keep per-request data on req or res.locals, not the shared app object.
Did you know?

res.app and req.app both point to the same Express application instance.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful