Express.js res.app Property

Last Updated : 31 Aug, 2026

The res.app property holds a reference to the Express application instance that is associated with the current response.

frame_3288

Syntax:

res.app

Parameter: No parameters. 

Return Value: Object 

Installation of the express module:

You can visit the link to Install the express module. You can install this package by using this command.

npm install express

After installing the express module, you can check your express version in the command prompt using the command.

npm version express

After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command.

node index.js

Project Structure:

NodeProj

Example 1: Filename: index.js 

javascript
const express = require('express');
const app = express();
const PORT = 3000;
app.set('title', 'GeeksforGeeks');
app.get('/', (req, res) => {
    console.log(res.app.get('title'));
    res.send('GeeksforGeeks');
});
app.listen(PORT, () => {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the program:

Run the index.js file using the below command:

node index.js

Output:

Console Output:

Server listening on PORT 3000

Browser Output:

Now open your browser and go to http://localhost:3000/, now you can see the following output on your browser:

Screenshot-2026-08-14-120814

Console Output:

Screenshot-2026-08-14-120654


Example 2: Filename: index.js 

javascript
const express = require('express');
const app = express();
const PORT = 3000;
app.set('appName', 'GeeksforGeeks');
app.get('/getApp', (req, res) => {
    const application = res.app;
    console.log(application === app);
    console.log(application.get('appName'));
    res.send('GeeksforGeeks');
});
app.listen(PORT, () => {
    console.log(`Server listening on PORT ${PORT}`);
});

Steps to run the program:

Run the index.js file using the below command:

node index.js

Output:

Console Output:

Server listening on PORT 3000

Browser Output:

Now open your browser and make a GET request to http://localhost:3000/getApp, now you can see the following output on your browser:

Screenshot-2026-08-14-120814

Console Output:

Screenshot-2026-08-14-121155

Working of res.app

  • An Express application is created using express().
  • A request is handled by a route or middleware.
  • Express provides the response object through the res parameter.
  • The res.app property provides a reference to the associated Express application.
  • The application instance can be used to access application settings and methods.

Use Cases of res.app

  • Accessing application-level settings from a response handler.
  • Retrieving configuration values stored using app.set().
  • Accessing Express application methods through the response object.
  • Sharing application-level configuration across middleware and route handlers.
  • Checking or interacting with the Express application instance.

Reference: https://expressjs.com/en/4x/api.html#app.mountpath

Comment