In Express.js, express.Router() creates a mini-application for middleware and routing only. You add get/post/… routes on the router, then mount it with app.use('/prefix', router).
Official docs: a router behaves like middleware, so you can also nest routers. Every Express app also has a built-in router; this page focuses on creating modular route files with express.Router().
Syntax
Read app.router in your Express.js route handler. Start with this line.
Required. Keep parent req.params. Child values win on name conflicts.
strict
Required. When true, /foo and /foo/ are different.
Return Value
Creating a router (via express.Router() / the app router APIs shown on this page) returns a Router instance. Its method APIs match the app (get, post, all, route, param, …).
GET /orgs/acme/teams
→ { "orgId": "acme", "teamId": null }
GET /orgs/acme/teams/ops
→ { "orgId": "acme", "teamId": "ops" }
Without mergeParams: orgId would be missing inside the child router.
How It Works
Parent param. Mount path includes :orgId.
mergeParams: true. Child keeps req.params.orgId.
Child param.:teamId is added on the nested route.
Conflicts. If both defined the same name, the child’s value wins.
Compatibility
Runtime Support
express.Router() is an Express.js API. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only hit the mounted URLs.
✓ Server · Express 4 & 5
express.Router()
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
RouterExpress on Node.js
Bottom line: Create a router, mount with app.use('/prefix', router), then request the full path.
Frequently Asked Questions
A Router is a mini-application that only does middleware and routing. You add routes to it, then mount it with app.use('/prefix', router).
const router = express.Router(); define router.get/post/…; then app.use('/api', router). Requests to /api/… are handled by that router.
When true, the child router keeps parent req.params. If names conflict, the child’s value wins. Default is false.
No. app.route(path) chains verbs on one path. express.Router() is a whole module of routes you can mount under a prefix.