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.

Syntax:
app.mountpathParameter: 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 expressAfter installing the express module, you can check your express version in the command prompt using the command.
npm version expressAfter 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.jsProject Structure:

Example 1: Getting the Mount Path of a Sub-Application
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.jsOutput:
Console Output:
Server listening on PORT 3000Browser Output: Now open your browser and go to http://localhost:3000/user, now you can see the following output on your console:

Console Output:

Example 2: Getting Multiple Mount Paths
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.jsOutput:
Console Output:
Server listening on PORT 3000Browser Output: Now open your browser and make a GET request to http://localhost:3000, now you can see the following output on your console:

Console Output:

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