req.params
An object of named route parameters captured from the URL path.
Syntax
req.params Returns
object — Maps each route param name to its string value.
Examples
app.get('/users/:id/posts/:postId', (req, res) => {
res.json(req.params);
});
Output
$ curl localhost:3000/users/7/posts/42
{"id":"7","postId":"42"}
app.get('/files/*splat', (req, res) => {
res.send(req.params.splat.join('/'));
});
Output
$ curl localhost:3000/files/a/b/c.txt
a/b/c.txt
Notes
All values are strings - convert with `Number()` as needed. In
Express 5 wildcards must be named (`*splat`) and the captured value
is an array of segments. Always validate params before using them in
queries.