In Express.js, express.Router() creates a new router — a mini-application that only does middleware and routing. You add get, post, use, and other handlers on it, then mount the whole stack with app.use('/prefix', router).
Use it to split features into files (users API, admin API, calendar) without putting every route on the top-level app. A router also works as middleware, so you can nest routers with router.use().
Syntax
Call express.Router in your Express.js app. Start with this line.
Express
express.Router([options])
Call
What it does
express.Router([options])
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.
Optional. Router behavior settings. Omit for defaults.
options.caseSensitive
Optional. Default false: /Foo and /foo match the same. true treats them as different.
options.mergeParams
Optional. Default false. true keeps parent req.params in the child. On name conflicts, the child value wins.
options.strict
Optional. Default false: /foo and /foo/ are the same. true treats trailing slashes as different.
Return Value
express.Router([options]) returns a new router instance. Pass an optional options object to control case sensitivity, trailing slashes, and parent param merging.
GET /user/42/comments
→ mergeParams keeps userId
→ Response: Comments for user 42
(Without mergeParams: true, req.params.userId is missing in the child)
How It Works
Parent owns the param./user/:userId captures the id on the parent mount.
Child opts in.express.Router({ mergeParams: true }) copies parent params into the child.
Child route stays short.child.get('/comments') only cares about the suffix.
Read the merged param.req.params.userId works inside the child handler. If names clash, the child’s value wins.
Compatibility
Runtime Support
express.Router() is an Express.js factory on the express module. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it.
✓ 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. 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
express.Router()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It creates a new router — a mini-app that holds middleware and routes. You mount it on the main app (or another router) with app.use() or router.use().
The app is the full Express application (settings, listen, engines). A Router only does middleware and routing, so you can split APIs into modules.
With mergeParams: true, a child router keeps parent path params on req.params. If both define the same name, the child’s value wins.
No. Defaults are fine for most apps: case-insensitive paths, trailing slashes treated the same, and no parent param merge.
No. Routers run on your Node.js server. Browsers only send HTTP requests to the mounted paths.