Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Pipe

req.app

req.app is a reference to the Express application instance that is using the middleware. Reusable middleware can use it to access application settings and other app-level APIs.

How it works

Inside middleware, req.app points to the Express application instance handling the current request. This lets reusable middleware access application settings and other app-level APIs without importing the app module.

Syntax

req.app

Key points

  • req.app references the Express application instance that is handling the current middleware.
  • A middleware module can export its function independently and still reach the active application through req.app.
  • The request property provides the middleware’s access path to the Express instance.

Example: Read the Express application from middleware

const express = require('express');
const app = express();

app.set('featureName', 'reports');
app.use((req, res) => {
  res.json({
    applicationSetting: req.app.get('featureName'),
    sameApplication: req.app === app
  });
});

app.listen(3000);

Run the server and request any path to read an application setting through req.app and verify that it references the same Express application.

When to use it

Access app settings

A reusable middleware needs an application setting without importing the application module.

Keep middleware decoupled

Middleware must use an app-level API while remaining usable across applications.

Interview questions

QWhat does req.app contain?

req.app is a reference to the Express application instance that is using the middleware. Middleware can use it to access app-level APIs such as settings.

Follow-up: How can middleware read an application setting? Use req.app.get with the setting name, for example req.app.get('views').

QHow can a separately exported middleware function access the Express app?

A reusable middleware module can export a middleware function and access the application through the request object. This avoids requiring the application instance directly in that module.

Follow-up: Why is this useful for reusable middleware? It keeps the middleware decoupled from a specific app module while still allowing access to the active application.

QWhat type and relationship does req.app have?

The property has the Application type and identifies the app instance associated with the current middleware execution. It is available through the request object as req.app.

Follow-up: What related property exposes the application through the response? Express also exposes the same application through res.app.

  • res.app
  • app.get()
  • Application Object
  • Request Object

Source: Request Object · Express.js 4.x. Checked 2026-10-15.