Express.js app.mountpath Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

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.

Express
app.use('/blog', blog)
blog.mountpath        // '/blog'
app.use(['/admin', '/manager'], admin)
admin.mountpath       // ['/admin', '/manager']
blog.use('/admin', blogAdmin)
blogAdmin.mountpath   // '/admin'  (relative to blog)
CallWhat it does
app.use('/blog', blog)Primary signature.
blog.mountpath // '/blog'Related call form.
app.use(['/admin', '/manager'], admin)Related call form.
admin.mountpath // ['/admin', '/manager']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();

app.use('/blog', blog)
blog.mountpath        // '/blog'
app.use(['/admin', '/manager'], admin)
admin.mountpath       // ['/admin', '/manager']
blog.use('/admin', blogAdmin)
blogAdmin.mountpath   // '/admin'  (relative to blog)

Parameters

ParameterDescription
app.use('/blog', blog)Required. blog.mountpath === '/blog'
blog.use('/admin', blogAdmin)Required. blogAdmin.mountpath === '/admin' (not /blog/admin)
app.use(['/a', '/b'], shared)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.

Express
const express = require('express');
const app = express();
const blog = express();
const blogAdmin = express();

blogAdmin.get('/', (req, res) => {
  res.json({
    blogAdminMountpath: blogAdmin.mountpath,
    blogMountpath: blog.mountpath,
    blogPath: blog.path(),
    blogAdminPath: blogAdmin.path(),
    baseUrl: req.baseUrl
  });
});

blog.use('/admin', blogAdmin);
app.use('/blog', blog);

app.listen(3000);

How It Works

  1. Two mounts. Parent mounts blog at /blog; blog mounts blogAdmin at /admin.
  2. Local patterns. blogAdmin.mountpath is only /admin — its parent’s prefix.
  3. path() chain. blogAdmin.path() concatenates to /blog/admin.
  4. Request prefix. req.baseUrl matches the full mount strip for this request.

Example 2 — Multi-Path Admin

One sub-app, two entry points — mountpath is an array; baseUrl follows the request.

Express
const express = require('express');
const app = express();
const admin = express();

admin.get('/', (req, res) => {
  res.json({
    mountpath: admin.mountpath,
    baseUrl: req.baseUrl,
    originalUrl: req.originalUrl
  });
});

app.use(['/admin', '/manager'], admin);
app.listen(3000);

How It Works

  1. Array mount. Parent registers the same sub-app on two prefixes.
  2. Patterns stay on the app. admin.mountpath lists both.
  3. baseUrl tracks the hit. Each request shows which prefix matched.
  4. originalUrl. Full incoming URL for comparison in logs.

Example 3 — Debug Middleware

Log the debug trio on every sub-app request without changing handlers.

Express
const express = require('express');
const app = express();
const api = express();

api.use((req, res, next) => {
  console.log({
    mountpath: api.mountpath,
    path: api.path(),
    baseUrl: req.baseUrl,
    url: req.url
  });
  next();
});

api.get('/users', (req, res) => {
  res.json({ ok: true });
});

app.use('/api/v1', api);
app.listen(3000);

How It Works

  1. Sub-app middleware. Runs for every request that enters api.
  2. mountpath / path(). Confirm how the parent mounted this module.
  3. baseUrl / url. Split the public URL into mount strip + remainder.
  4. next(). Continue to GET /users on the sub-app.

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.

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

Next: app.param()

Run middleware when a route parameter is present.

app.param() tutorial →

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