In Express.js, this page goes deeper than the app.mountpath intro. You already know subApp.mountpath stores the path pattern(s) from parent.use(...). Here the focus is nested mounts, multi-path mounts, and safe debugging with req.baseUrl and app.path().
Each sub-app only sees the pattern its immediate parent used. The full public URL is the chain of mounts plus the route — for a single request, req.baseUrl is usually the clearest prefix.
Syntax
Read app.mountpath in your Express.js route handler. Start with this line.
Required. shared.mountpath is an array; req.baseUrl is the one that matched
Return Value
app.mountpath returns the path pattern where this app was mounted. For the top-level app it is typically empty-related behavior on related APIs; for a sub-app mounted at /blog, you get that segment — not always the full public URL chain.
Express
const blog = express();
app.use('/blog', blog);
blog.mountpath; // '/blog'
// Nested mount: each app sees its immediate mount segment
Express.js Examples
Example 1 — Nested Blog / Admin
Official-style nesting: each layer reports its own mountpath; app.path() shows the chain.
Sub-app middleware. Runs for every request that enters api.
mountpath / path(). Confirm how the parent mounted this module.
baseUrl / url. Split the public URL into mount strip + remainder.
next(). Continue to GET /users on the sub-app.
Compatibility
Runtime Support
app.mountpath is an Express.js application property. Nested mounts work the same on Node.js (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.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
app.mountpathExpress on Node.js
Bottom line: Run nested examples with Node.js and express, then hit paths like /blog/admin or /api/v1/users.
Frequently Asked Questions
After the basics on /express/app-mount. This page focuses on nested mounts, multiple patterns, and debugging with req.baseUrl and app.path().
Each sub-app reports the pattern used by its immediate parent. Nested apps each have their own mountpath — they do not automatically show the full chain.
Official guidance notes app.path() can get complicated with nested mounts. req.baseUrl gives the matched URL prefix for the current request.
Yes. When a parent mounts with app.use(['/a', '/b'], subApp), that sub-app’s mountpath is an array of those patterns.
Prefer req.baseUrl (or known constants) for request-time URLs. Treat mountpath as mount metadata for logs and diagnostics.