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

Express.js · Module

res.get

Reads a response header from Express's res object by name. Header-name matching is case-insensitive, and the method returns the selected header value.

How it works

Call res.get() inside a handler to read a response header previously available on the outgoing response. Pass the header name as a string; matching ignores letter case, and the method returns the selected header value.

Syntax

res.get(field)

Parameters

NameTypeDescription
fieldStringName of the response header to read; matching is case-insensitive.

Returns

String: the HTTP response header specified by field.

Key points

  • The method returns the value of the response header identified by its argument.
  • Its field argument is the name of a response header, and capitalization is ignored.
  • Call the method with a header-name string, such as Content-Type.
  • res.get() operates on the outgoing HTTP response represented by Express's res object.

Common mistakes

  • Header-name capitalization does not affect the lookup.

Example: Read a response header

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

app.get('/', (req, res) => {
  res.set('Content-Type', 'text/plain');
  res.send(`Stored type: ${res.get('Content-Type')}`);
});

app.listen(3000);

Starts an Express server, sets a response header, reads it case-insensitively with res.get(), and includes the value in the response.

When to use it

Inspect response metadata

Middleware or a route needs to inspect an outgoing header before completing the response.

Validate headers

Application diagnostics need to verify the value assigned to a response header.

Case-insensitive lookup

Code should read a header without depending on its capitalization.

Interview questions

QWhat does res.get() do?

res.get(field) reads the HTTP response header named by field and returns its value as a string. The lookup is case-insensitive, so different capitalization of the same header name works.

Follow-up: What happens if the header has not been set? The page does not specify a missing-header return behavior, so avoid assuming a particular value without checking the relevant runtime behavior.

QWhat argument does res.get() accept?

The argument is the response-header name, represented as a String. The method reads from the Express response object associated with the current request handler.

Follow-up: Why is the response object available in a route handler? Express passes it as the handler's res parameter, whose actual variable name can differ.

QGive a practical use for res.get().

A typical use is to inspect a response header after setting it, for example reading Content-Type before composing or logging a response. The returned value is the HTTP response header specified by the field argument.

Follow-up: How would you obtain a request header instead? Use the request object's header-reading API rather than res.get(), because res.get() targets the outgoing response.

  • res.set()
  • res.header()
  • res.append()
  • res.type()
  • res.send()

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