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

Express.js · Module

req.get

Retrieves the value of an HTTP request header by name. Use it inside a route or middleware callback to inspect client-supplied request metadata.

How it works

req.get() retrieves the value of a named HTTP request header. Header-name matching is case-insensitive, and the method returns the header value when present or undefined when absent.

Syntax

req.get(field)

Parameters

NameTypeDescription
headerstringThe name of the HTTP request header to retrieve.

Returns

The value of the requested header, or undefined when the header is not present.

Key points

  • The request object exposes request metadata, including headers that req.get() can inspect.
  • req.get() is one of the request methods available for working with incoming HTTP requests.
  • Call the method on the request object supplied to a route or middleware callback.

Common mistakes

  • req includes Node’s built-in request capabilities, so use req.get() specifically when you want Express’s header lookup helper.

Example: Read a request header

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

app.get('/profile', (req, res) => {
  const userAgent = req.get('User-Agent');
  res.json({ userAgent });
});

app.listen(3000);

Reads the request's User-Agent header and returns it as JSON.

When to use it

Client identification

Inspect the User-Agent sent by a client.

Content negotiation

Read an Accept or Content-Type-related request header.

Custom request metadata

Use a custom header to apply request-specific logic.

  • req
  • req.headers
  • req.header
  • app.get
  • router.get

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