Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Const

req.params

req.params is an object containing values captured by named parameters in the matched Express route. Named captures use parameter-name properties, while regular-expression captures can use numeric keys.

How it works

Express fills req.params with values captured by named segments in the matched route path. The property is an object whose keys are parameter names; regular-expression routes can additionally expose capture groups through numeric keys.

Syntax

req.params

Returns

An object containing values captured from the matched route's parameters.

Key points

  • req.params is the request property that maps captured named route parameters to their values.
  • A :name segment is read through req.params.name after the route matches.
  • A named regex capture can be accessed like a named route parameter.

Common mistakes

  • A request with no captured route parameters still receives an object, initialized as an empty object.
  • Use app.param when changing a parameter value; changes do not create arbitrary new route-parameter keys.

Example: Read named route parameters

const express = require('express');
const app = express();

app.get('/users/:userId/books/:bookId', (req, res) => {
  res.json({ userId: req.params.userId, bookId: req.params.bookId });
});

app.listen(3000);

This route reads both named URL segments from req.params and returns them as JSON.

When to use it

Read a resource identifier

A route such as /users/:userId needs to identify the requested user.

Handle nested resources

A nested route captures multiple URL segments such as /users/:userId/books/:bookId.

Consume regex route captures

A route uses a regular expression with capture groups.

Interview questions

QWhat does req.params contain?

Express populates req.params from named parameters in the matched route path. For /user/:name, the captured value is available as req.params.name.

Follow-up: How are unnamed regular-expression captures accessed? They are exposed with integer keys such as req.params[0], where the index identifies the capture group.

QWhat is the shape and default value of req.params?

It is an object, and with string route paths its default value is {}. Each named route parameter becomes a property whose value is the corresponding captured URL segment.

Follow-up: What happens when a route uses a regular expression? The object remains standard and capture groups are available through numeric keys.

QHow should an application modify route parameters?

Use app.param when parameter-specific processing or changes are needed. Such changes apply only to parameters that the route path already defines.

Follow-up: Can app.param add an unrelated key to req.params? No; the documented behavior applies only to parameters already defined in the route path.

  • app.param
  • req.query
  • req.body
  • req.route

Source: Request - Express.js 4.x. Checked 2026-10-15.