Legacy compatibility
Maintaining an older Express 4 application that already uses the convenience lookup.
Express.js · Module
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.
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.
req.param(name, defaultValue)| Name | Type | Description |
|---|---|---|
name | String | String name to find in route parameters, the parsed body, and the query string. |
defaultValue | any | undefined | Value returned when the name is absent from all request objects. |
any
name argument.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.
Maintaining an older Express 4 application that already uses the convenience lookup.
Checking a value across supported request locations during a gradual migration.
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.
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.
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.paramsreq.bodyreq.query