router.param(name, callback) adds a trigger for a named route parameter such as :id or :user on an express.Router(). When a matching route on that router runs, Express calls your callback before the route handlers — ideal for validation and loading data into req.
The callback signature is (req, res, next, value, name). Pair it with router.METHOD() paths and values in req.params. The app-level twin is app.param().
Syntax
Call router.param in your Express.js app. Start with this line.
Express
router.param(name, callback)
Call
What it does
router.param(name, callback)
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 /members/profile/ada
→ { "name": "Ada", "role": "admin" }
GET /members/profile/nobody
→ 404 User not found
How It Works
Named param user. Matches routes on this router with :user.
Lookup. Find the record (here a plain object; in apps often a DB call).
Attach. Set req.user so the route stays thin.
404 early. Missing users never reach the JSON handler. The mount makes the public path /members/profile/:user.
Compatibility
Runtime Support
router.param() is an Express.js router method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the URL that contains the parameter.
✓ Server · Express 4 & 5
router.param()
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
router.param()Express on Node.js
Bottom line: Run examples with Node.js and the express package, then request paths like /users/42.
Frequently Asked Questions
It registers a callback that runs when a named route parameter (like :id) appears on that router’s routes, before the route handlers.
Behavior is the same for a single name, but router.param() is scoped to one router and does not accept an array of names. app.param() can register the same callback for several names at once.
No. Even if several routes on the router match the same param name, the param callback runs only once per request-response cycle.
No. Param callbacks are local. They are not triggered for parameters defined only on a parent router, even when mergeParams makes those values visible on req.params.
No. It is server-side Express middleware wired to route parameters on Node.js.