Home Express.js Application app.mountpath Express.js app.mountpath Property Definition In Express.js, app.mountpath holds the path pattern(s) where a sub-app was mounted on its parent with app.use() . A sub-app is another express() instance used as middleware.
It is similar to req.baseUrl , except mountpath stores the mount patterns , while req.baseUrl is the matched URL path for the current request. For a longer walkthrough, see app.mountpath (detailed) .
Syntax Read app.mountpath in your Express.js route handler. Start with this line.
subApp.mountpath // '/admin' or ['/admin', '/manager']
app.use('/admin', subApp)
app.use(['/admin', '/manager'], subApp) Call What it does subApp.mountpath // '/admin' or ['/admin', '/manager']Primary signature. app.use('/admin', subApp)Related call form. app.use(['/admin', '/manager'], subApp)Related 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 const express = require("express");
const app = express();
subApp.mountpath // '/admin' or ['/admin', '/manager']
app.use('/admin', subApp)
app.use(['/admin', '/manager'], subApp) Parameters Parameter Description Mounted once: app.use('/admin', admin) Required. '/admin' (string) Mounted on several patterns: app.use(['/admin', '/manager'], admin) Required. ['/admin', '/manager'] (array) Top-level app (not mounted as a sub-app) Required. Not useful for mount debugging — prefer routes / req.baseUrl
Return Value app.mountpath is a property (string, or sometimes an array/pattern) that reports where this app was mounted by a parent. Reading it returns that mount path — it is not a method that returns app.
// parent.js
const admin = express();
app.use('/admin', admin);
// inside admin setup / a request:
admin.mountpath; // '/admin' Express.js Examples 1. Mount /admin 2. Multiple mount paths 3. mount event + baseUrl Example 1 — Mount /admin Official-style sub-app: log mountpath when the admin homepage runs.
const express = require('express');
const app = express();
const admin = express();
admin.get('/', (req, res) => {
console.log(admin.mountpath); // /admin
res.send('Admin Homepage');
});
app.use('/admin', admin);
app.listen(3000); GET /admin
Console: /admin
Body: Admin Homepage How It Works Two apps. Parent app and sub-app admin.Route on the sub-app. admin.get('/') is the sub-app homepage.Mount. app.use('/admin', admin) attaches it under /admin.Read metadata. Inside the handler, admin.mountpath is '/admin'.Example 2 — Multiple Mount Paths One sub-app mounted on an array of patterns — mountpath becomes an array.
const express = require('express');
const app = express();
const admin = express();
admin.get('/', (req, res) => {
console.log(admin.mountpath);
// ['/admin', '/manager']
res.json({ mountpath: admin.mountpath, baseUrl: req.baseUrl });
});
app.use(['/admin', '/manager'], admin);
app.listen(3000); GET /admin
→ { "mountpath": ["/admin", "/manager"], "baseUrl": "/admin" }
GET /manager
→ { "mountpath": ["/admin", "/manager"], "baseUrl": "/manager" } How It Works Array mount. Parent mounts admin on two prefixes.Patterns on the app. admin.mountpath lists both patterns.Request prefix. req.baseUrl is whichever path matched this request.Same handler. Both URLs hit the same sub-app route.Example 3 — mount Event + baseUrl Listen for the mount event, then compare mountpath with req.baseUrl on a request.
const express = require('express');
const app = express();
const admin = express();
admin.on('mount', (parent) => {
console.log('Admin mounted');
console.log('parent === app?', parent === app); // true
});
admin.get('/dashboard', (req, res) => {
res.json({
mountpath: admin.mountpath,
baseUrl: req.baseUrl,
url: req.url
});
});
app.use('/admin', admin);
app.listen(3000); On startup:
Admin mounted
parent === app? true
GET /admin/dashboard
→ {
"mountpath": "/admin",
"baseUrl": "/admin",
"url": "/dashboard"
} How It Works mount event. Fires when the parent mounts the sub-app; parent is the parent app.Relative route. /dashboard on the sub-app is reached as /admin/dashboard.mountpath. Still the pattern /admin.baseUrl vs url. req.baseUrl is the mount strip; req.url is the remainder.Compatibility
Runtime Support app.mountpath is an Express.js application property . It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers never read it.
✓ Server · Express 4 & 5
app.mountpath Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.
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 app.mountpath Express on Node.js
Bottom line: Run these examples with Node.js and the express package, then request the mounted path (for example /admin).
Frequently Asked Questions What is Express.js app.mountpath? It is a property on a sub-app that lists the path pattern(s) where the parent mounted it with app.use. Type is String or String[].
How is mountpath different from req.baseUrl? mountpath is the mount pattern(s) on the app. req.baseUrl is the matched URL path for the current request.
When does mountpath become meaningful? After the parent mounts the sub-app with app.use('/prefix', subApp). Before that, it is not useful for debugging mounts.
Can one sub-app have multiple mount paths? Yes. If you mount with an array of paths, mountpath is an array of those patterns.
Can browsers read app.mountpath? No. It is server-side metadata on your Express app instance.
Next: app.mountpath (detailed) Go deeper on multi-pattern mounts and nested sub-apps.
Detailed mountpath → CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion