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

Express.js · Interface

Request

The Express req object represents an incoming HTTP request. It exposes route parameters, query data, body data, headers, request metadata, and helpers for inspecting or negotiating the request.

How it works

Express supplies the incoming request to route and middleware callbacks as req. The object extends Node’s request object and exposes request metadata, parsed route and query values, body data when body-parsing middleware is used, headers, and helper methods such as get() and accepts().

Syntax

(req, res, next)

Parameters

NameTypeDescription
reqRequestThe incoming HTTP request supplied to a route or middleware callback.

Returns

An Express request object containing request properties and methods.

Key points

  • Use req to inspect data and metadata associated with the incoming HTTP request.
  • Express adds request conveniences without removing the capabilities inherited from Node’s request object.
  • req.params maps each named route placeholder to the value captured from the URL.
  • req.body represents submitted body fields after body-parsing middleware has populated it.
  • req.method reports the request method, including values such as GET, POST, and PUT.
  • req.app lets middleware access the Express application instance handling the request.

Common mistakes

  • req.body is unavailable until suitable body-parsing middleware, such as express.json() or express.urlencoded(), processes the request.
  • Uploaded files are not provided through req.files automatically; use multipart-handling middleware when needed.

Example: Read request data

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

app.get('/users/:name', (req, res) => {
  res.json({
    name: req.params.name,
    query: req.query,
    method: req.method,
    userAgent: req.get('User-Agent')
  });
});

app.listen(3000);

Run the server, then request /users/Ada?active=true to see route parameters, query data, the HTTP method, and a header.

When to use it

Read route parameters

A route needs values captured from a URL pattern such as /users/:id.

Process query strings

An endpoint filters or paginates results using values after ? in the URL.

Inspect request headers

Middleware needs to inspect authorization, content type, or another incoming header.

Perform content negotiation

A handler selects a response representation based on the client’s Accept header.

Interview questions

QHow do req.params, req.query, and req.body differ?

req.params contains values captured from named route segments, such as :name. req.query contains parsed query-string values, while req.body contains submitted body data only after body parsing.

Follow-up: How would you read a request header? Use req.get(field), which performs a case-insensitive lookup; the documentation also treats Referrer and Referer as interchangeable.

QWhich request properties expose method, protocol, and headers?

req.method identifies the HTTP method, such as GET or POST. req.protocol identifies http or https, and req.get() retrieves a request-header value.

Follow-up: How can content negotiation be checked? Call req.accepts(types) to find the best acceptable type, or handle an undefined result as a 406 response.

QWhat is the relationship between Express’s request object and Node’s request object?

Express’s request object is enhanced from Node’s own request object, so it retains Node’s built-in fields and methods while adding Express-specific properties and helpers. It is conventionally named req, but the callback parameter can use another name.

Follow-up: What does req.app provide? It references the Express application instance that is using the middleware.

  • req.app
  • req.body
  • req.get(field)
  • req.method
  • req.params
  • req.protocol
  • req.query
  • req.res

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