app.mountpath contains the path pattern(s) on which a sub-application is mounted.
Syntax
app.mountpath
Example
const express = require("express");
const app = express();
const adminApp = express();
const PORT = 4900;
adminApp.get("/", (req, res) => {
console.log(adminApp.mountpath); // /admin
res.send("Admin sub-app home");
});
app.use("/admin", adminApp);
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
Multiple mount paths
app.use(["/admin", "/backoffice"], adminApp);
Here, adminApp.mountpath becomes ["/admin", "/backoffice"].
Use cases
- Identifying where a sub-application is mounted.
- Debugging apps composed of multiple sub-applications.
- Supporting a sub-app mounted on more than one path.