Express.js app.mountpath Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

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.

Express
subApp.mountpath   // '/admin'  or  ['/admin', '/manager']
app.use('/admin', subApp)
app.use(['/admin', '/manager'], subApp)
CallWhat 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
Express
const express = require("express");
const app = express();

subApp.mountpath   // '/admin'  or  ['/admin', '/manager']
app.use('/admin', subApp)
app.use(['/admin', '/manager'], subApp)

Parameters

ParameterDescription
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.

Express
// parent.js
const admin = express();
app.use('/admin', admin);

// inside admin setup / a request:
admin.mountpath; // '/admin'

Express.js Examples

Example 1 — Mount /admin

Official-style sub-app: log mountpath when the admin homepage runs.

Express
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);

How It Works

  1. Two apps. Parent app and sub-app admin.
  2. Route on the sub-app. admin.get('/') is the sub-app homepage.
  3. Mount. app.use('/admin', admin) attaches it under /admin.
  4. 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.

Express
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);

How It Works

  1. Array mount. Parent mounts admin on two prefixes.
  2. Patterns on the app. admin.mountpath lists both patterns.
  3. Request prefix. req.baseUrl is whichever path matched this request.
  4. 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.

Express
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);

How It Works

  1. mount event. Fires when the parent mounts the sub-app; parent is the parent app.
  2. Relative route. /dashboard on the sub-app is reached as /admin/dashboard.
  3. mountpath. Still the pattern /admin.
  4. baseUrl vs url. req.baseUrl is the mount strip; req.url is the remainder.

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

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[].
mountpath is the mount pattern(s) on the app. req.baseUrl is the matched URL path for the current request.
After the parent mounts the sub-app with app.use('/prefix', subApp). Before that, it is not useful for debugging mounts.
Yes. If you mount with an array of paths, mountpath is an array of those patterns.
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.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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