Express.js app.mountpath Property

Last Updated : 31 Aug, 2026

The app.mountpath property contains the path pattern or path patterns on which a sub-application is mounted. It is useful for identifying the mount path of an Express sub-application.

frame_10

Syntax:

app.mountpath

Parameter: No parameters. 

Return Value: Returns a String or Array of strings containing the path pattern(s) on which the sub-application is mounted. 

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: Getting the Mount Path of a Sub-Application

javascript
const express = require('express');
const app = express();  // the main app
const user = express(); // the sub app
const PORT = 3000;
user.get('/', function (req, res) {
      console.log(user.mountpath); // /user
      res.send('User Homepage');
});
app.use('/user', user); // Mounting the sub app
app.listen(PORT, function(err){
    if (err) console.log(err);
    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/user, now you can see the following output on your console:

Screenshot-2026-08-19-101239

Console Output:

Screenshot-2026-08-19-101019

Example 2: Getting Multiple Mount Paths

javascript
const express = require('express');
const app = express();
const user = express(); // the sub app
const PORT = 3000;
user.get('/', function (req, res) {
    console.log(user.mountpath);
    res.send('User Homepage');
});
app.use(['/user', '/admin'], user); // Mounting the sub app on multiple paths
app.listen(PORT, function (err) {
    if (err) console.log(err);
    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, now you can see the following output on your console:

Screenshot-2026-08-19-101239

Console Output:

Screenshot-2026-08-19-102735

Working of app.mountpath

  • An Express sub-application is created using express().
  • The sub-application is mounted on a path using app.use().
  • Express stores the path pattern on which the sub-application is mounted.
  • If the sub-application is mounted on multiple path patterns, app.mountpath returns an array containing those patterns.

Use Cases of app.mountpath

  • Identifying the path on which a sub-application is mounted.
  • Working with applications that contain multiple sub-applications.
  • Checking the mount path when debugging routing configurations.
  • Handling applications where a sub-application is mounted on multiple paths.

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

Comment