app.path() returns the canonical path of an Express app as a string — how it sits in a parent mount chain. The top-level app returns ''; a sub-app mounted at /blog returns '/blog'.
Required. Canonical mount path for this app. Root: ''. Nested example: '/blog/admin'.
Return Value
app.path() takes no arguments and returns a String: the canonical mount path built from parent mounts. The root app returns an empty string (''), not '/'.
Express
app.path(); // '' on the top-level app
const admin = express();
app.use('/admin', admin);
admin.path(); // '/admin'
GET /blog/posts
→ {
"pathMethod": "/blog",
"baseUrl": "/blog",
"tip": "Prefer req.baseUrl in handlers"
}
How It Works
Mount. Blog lives under /blog.
path(). Reports the app’s place in the tree (startup-friendly).
baseUrl. Comes from the current match — safer for redirects and links.
Docs tip. When mounts get complex, lean on req.baseUrl.
Compatibility
Runtime Support
app.path() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only hit the mounted URLs.
✓ Server · Express 4 & 5
app.path()
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.path()Express on Node.js
Bottom line: Run examples with Node.js and the express package, then log app.path() after mounts.
Frequently Asked Questions
A string: the canonical path of that app in the mount hierarchy. The root app returns an empty string ''.
mountpath is the pattern used when this app was mounted by its parent (string or array). path() walks parents and joins those mounts into one canonical string.
Usually prefer req.baseUrl. Official docs note path() can get complicated with complex mounts; baseUrl is the matched URL prefix for the current request.
No. It reflects how apps are mounted, not the current request URL.
No. It is a server-side Express application method on Node.js.