Express.js res.app Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Response

Definition

res.app holds a reference to the Express application that is using the middleware — the same object you create with express().

Officially it is identical to req.app: res.app === req.app is true. Use it to read settings (res.app.get('view engine')), locals, or other app APIs when you are working from the response side.

Syntax

Read res.app in your Express.js route handler. Start with this line.

Express
res.app
res.app.get(name)
res.app.set(name, value)
res.app.locals
res.app === req.app   // → true
CallWhat it does
res.appPrimary signature.
res.app.get(name)Related call form.
res.app.set(name, value)Related call form.
res.app.localsRelated call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

res.app
res.app.get(name)
res.app.set(name, value)
res.app.locals
res.app === req.app   // → true

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

res.app is a property referring to the Express application that created this response — the same app instance you configure at startup.

Express
const env = res.app.get('env');
res.locals.site = res.app.locals.title;

Express.js Examples

Example 1 — Read App Settings from res.app

Official-style access: pull view engine (or any setting) through the response.

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

app.set('view engine', 'ejs');
app.set('siteName', 'CodeToFun');

app.get('/', (req, res) => {
  res.json({
    viewEngine: res.app.get('view engine'),
    site: res.app.get('siteName')
  });
});

app.listen(3000);

How It Works

  1. Configure the app. app.set stores settings on the application instance.
  2. Reach it from res. res.app is that same instance during the request.
  3. Read with .get. res.app.get('view engine') returns what you set (here 'ejs').
  4. Respond. Settings are available anywhere you have res — no global import required.

Example 2 — Prove res.app === req.app

Confirm the docs: both properties point at one application object.

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

app.get('/same-app', (req, res) => {
  console.dir(res.app === req.app); // true
  res.json({
    same: res.app === req.app,
    env: res.app.get('env')
  });
});

app.listen(3000);

How It Works

  1. Two properties, one app. Express attaches the same reference on req and res.
  2. Strict equality. === compares object identity — result is true.
  3. Either side works. res.app.get('env') and req.app.get('env') return the same value.
  4. Pick for readability. Use res.app when the code is response-centric.

Example 3 — Helper That Only Receives res

When a utility is given only the response, res.app still reaches app config.

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

app.set('siteName', 'CodeToFun');

function sendAbout(res) {
  const name = res.app.get('siteName');
  res.locals.page = 'about'; // per-response data
  res.json({ site: name, page: res.locals.page });
}

app.get('/about', (req, res) => {
  sendAbout(res);
});

app.listen(3000);

How It Works

  1. Helper signature. sendAbout(res) does not receive req or close over app.
  2. App via res.app. Shared config still comes from res.app.get('siteName').
  3. Per-request on res.locals. page belongs to this response only — not on the app.
  4. Clear separation. App settings stay global; locals stay request-scoped.

Runtime Support

res.app is an Express.js response property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not have this API.

✓ Server · Express 4 & 5

res.app

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
res.app Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is a reference on the response object to the Express application instance that is using the middleware — the same object you create with express().
Yes. Officially res.app is identical to req.app. For a given request, res.app === req.app is true.
Call res.app.get('settingName'), the same settings API as app.get / app.set. For example res.app.get('view engine').
Use whichever object you already have in scope. Prefer res.app when the handler is focused on building the response, or when only res is passed into a helper.
No. It is a server-side Express property. Browsers only receive the HTTP response your app sends.

Next: res.append()

Append values to response headers without overwriting existing ones.

res.append() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful