Express.js req.params Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.params is an object of values captured from named route segments. For /user/:name and a request to /user/tj, you get req.params.name === 'tj'.

Define placeholders in routes registered with app.get() (or other methods), then read them in the handler. For shared param logic, use app.param(). Query-string values belong on req.query, not here.

Syntax

Read req.params in your Express.js route handler. Start with this line.

Express
req.params
req.params.name
req.params[0]   // capture group when the route is a RegExp
CallWhat it does
req.paramsPrimary signature.
req.params.nameRelated call form.
req.params[0] // capture group when the route is a RegExpRelated call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.params
req.params.name
req.params[0]   // capture group when the route is a RegExp

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

req.params is an object of route parameters. Values are strings — for example /users/34 on /users/:userId yields { userId: '34' }.

Express
app.get('/users/:userId', (req, res) => {
  const id = Number(req.params.userId);
});

Express.js Examples

Example 1 — Read One Route Parameter

Capture :name from the path, as in the official API sample.

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

app.get('/user/:name', (req, res) => {
  // GET /user/tj
  console.dir(req.params.name);
  // => 'tj'
  res.send('Hello, ' + req.params.name);
});

app.listen(3000);

How It Works

  1. Declare the placeholder. :name marks one path segment.
  2. URL fills the object. /user/tj sets req.params.name to 'tj'.
  3. Value is a string. Even digits would arrive as strings.
  4. Use it in the response. Send a greeting built from the param.

Example 2 — Several Named Parameters

Match nested resources the way the routing guide shows.

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

app.get('/users/:userId/books/:bookId', (req, res) => {
  // GET /users/34/books/8989
  // req.params → { userId: '34', bookId: '8989' }
  res.send(req.params);
});

app.listen(3000);

How It Works

  1. Name each segment. :userId and :bookId map to object keys.
  2. Order follows the path. First capture → userId, second → bookId.
  3. Both stay strings. Convert if you need numbers.
  4. Send the object. Handy for learning and quick APIs.

Example 3 — Named Wildcard (Express 5)

Capture the rest of the path as an array of segments.

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

app.get('/files/*file', (req, res) => {
  // GET /files/images/logo.png
  // req.params.file → [ 'images', 'logo.png' ]
  res.send('File: ' + req.params.file.join('/'));
});

app.listen(3000);

How It Works

  1. Name the wildcard. Express 5 uses *file (not a bare *).
  2. Segments become an array. Split on / into req.params.file.
  3. Join when you need a path. join('/') rebuilds a relative file path.
  4. Still validate. Never treat wildcard paths as trusted filesystem paths without checks.

Runtime Support

req.params is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only request URLs that your routes match.

✓ Server · Express 4 & 5

req.params

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.params Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is an object of values captured from named route segments in the path, such as :id in /users/:id.
Named parameters are strings (and Express URL-decodes them). Wildcard parameters are arrays of path segments.
req.params comes from the route path pattern. req.query comes from the ?key=value query string.
The old req.param(name) helper is removed in modern Express. Read req.params, req.query, or req.body explicitly instead.
No. It is a server-side Express request property. Browsers only request a URL; your app fills req.params when the route matches.

Next: req.path

Read the request pathname without the query string.

req.path tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful