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

Express.js · Module

req.param

req.param(name, defaultValue) retrieves a named value from route parameters, the request body, or the query string, in that order. It is deprecated; prefer reading the appropriate request property directly.

How it works

req.param(name, defaultValue) searches for a named value first in route parameters, then parsed request-body fields, and finally query-string fields. If no value exists, it returns the supplied default when provided. Express marks this convenience lookup as deprecated, so application code should select req.params, req.body, or req.query explicitly.

Syntax

req.param(name, defaultValue)

Parameters

NameTypeDescription
nameStringString name to find in route parameters, the parsed body, and the query string.
defaultValueany | undefinedValue returned when the name is absent from all request objects.

Returns

any

Key points

  • The method returns the value associated with the requested name when it can find one.
  • Its lookup key is the string supplied as the name argument.
  • The optional second argument supplies the result for a missing name.
  • The documented parameter name must be a string.
  • The fallback accepts any value and may be omitted.
  • Route values are available through the request's named parameter object.

Common mistakes

  • If the same name exists in multiple locations, the route parameter wins, followed by the body and then the query string.

Example: Looking up a request parameter

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

app.use(express.urlencoded({ extended: false }));

app.get('/users/:id', (req, res) => {
  const value = req.param('id', 'anonymous');
  res.send(value);
});

app.listen(3000);

Run the server, then request /users/42 to receive 42. The method is shown for compatibility; new code should use the specific request property instead.

When to use it

Legacy compatibility

Maintaining an older Express 4 application that already uses the convenience lookup.

Incremental migration

Checking a value across supported request locations during a gradual migration.

Interview questions

QWhat does req.param() do?

It accepts a parameter name and an optional fallback value. Express searches req.params, then req.body, then req.query, and returns the first matching value.

Follow-up: What should replace it? Read the intended source directly, such as req.params.id, req.body.name, or req.query.page, so the input origin is explicit.

QHow does the optional default value work?

The first argument is a string naming the value to find. The second argument can be any value or undefined; it is returned if the name is absent from all three request objects.

Follow-up: Why might a fallback be risky? A default can hide a missing required input, so validation should distinguish absent values from acceptable defaults.

QShould new Express code use req.param()?

The method is deprecated in Express 4. It remains documented, but the API advises using req.params, req.body, or req.query as appropriate.

Follow-up: How does Express 5 affect this API? Express 5 removes req.param(), requiring callers to read the appropriate request property directly.

  • req.params
  • req.body
  • req.query

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