In Express.js, req.baseUrl is the URL path on which the current router was mounted. If you mount with app.use('/greet', greetRouter), then inside that router req.baseUrl is /greet.
It is similar to app.mountpath, except mountpath can return the pattern(s) you registered, while req.baseUrl always returns the matched string for this request. It is a server-side property on the request object.
Syntax
Read req.baseUrl in your Express.js route handler. Start with this line.
Express
req.baseUrl
Call
What it does
req.baseUrl
Primary signature.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
GET /greet/jp
→ 200 { "baseUrl": "/greet", "message": "Konnichiwa!" }
GET /hello/jp
→ 200 { "baseUrl": "/hello", "message": "Konnichiwa!" }
How It Works
Register one router twice.app.use(['/greet', '/hello'], greet) accepts either prefix.
Match decides baseUrl. A hit to /greet/jp sets /greet; /hello/jp sets /hello.
Not the pattern list. Unlike app.mountpath, req.baseUrl is the concrete matched string for this request.
Same handler logic. The route /jp stays unchanged; only the mount prefix differs.
Compatibility
Runtime Support
req.baseUrl is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the URL; they do not see this property.
✓ Server · Express 4 & 5
req.baseUrl
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
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
req.baseUrlExpress on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Mount a router, then log req.baseUrl to see the prefix.
Frequently Asked Questions
It is the URL path on which the current router instance was mounted — for example /greet when you call app.use('/greet', greetRouter).
req.baseUrl is the mount prefix. req.path is the remaining path inside the current router (the mount point is not included).
req.originalUrl is the full original request URL path (plus query). It is effectively a combination of req.baseUrl and req.url.
Yes. On top-level app routes that are not under a mounted router, req.baseUrl is usually ''.
It returns the matched string for that request, not the pattern list. Mounted on ['/greet', '/hello'], a hit to /hello/jp gives baseUrl '/hello'.