Express.js res.get() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Response

Definition

In Express.js, res.get() returns the HTTP response header named by field. The match is case-insensitive. Use it to inspect headers already set with res.set(), res.type(), res.append(), or helpers like res.json().

It does not read the client’s request. For incoming headers, use req.get(). Call res.get() before the response is finished; after res.headersSent is true, treat the response as closed.

Syntax

Call res.get in your Express.js app. Start with this line.

Express
res.get(field)
res.get('Content-Type');
CallWhat it does
res.get(field)Primary signature.
res.get('Content-Type');Related 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();

res.get(field)
res.get('Content-Type');

Parameters

ParameterDescription
fieldRequired. Name of the response header to read (case-insensitive), for example Content-Type or Cache-Control.

Return Value

res.get(field) returns the outgoing response header value as a string, or undefined if you have not set it yet.

Express
res.type('json');
res.get('Content-Type'); // 'application/json; charset=utf-8' (typical)

Express.js Examples

Example 1 — Read a Header After Setting It

Set Cache-Control, then echo it back in JSON.

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

app.get('/cache', (req, res) => {
  res.set('Cache-Control', 'public, max-age=60');
  const cacheHeader = res.get('Cache-Control');
  res.json({ cache: cacheHeader });
});

app.listen(3000);

How It Works

  1. Write first. res.set stores the outgoing header on res.
  2. Read with get. res.get('Cache-Control') returns that string.
  3. Use the value. Here it is included in the JSON body for demonstration.
  4. Still one response. Headers and body go out together when json finishes.

Example 2 — Inspect a Header Set in Middleware

Earlier middleware sets a custom header; the route reads it with res.get.

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

app.use((req, res, next) => {
  res.set('X-App-Version', '1.0.0');
  next();
});

app.get('/version', (req, res) => {
  res.send('Version header: ' + res.get('X-App-Version'));
});

app.listen(3000);

How It Works

  1. Middleware writes. res.set('X-App-Version', …) runs for every request.
  2. next() continues. The route handler still sees the same res object.
  3. get reads it back. Useful for logging or building a message from earlier steps.
  4. Case does not matter. res.get('x-app-version') would return the same value.

Example 3 — Handle a Missing Header Safely

Check Content-Type before it is set; branch when get returns nothing.

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

app.get('/content-type-check', (req, res) => {
  const contentType = res.get('Content-Type');

  if (!contentType) {
    return res.type('text').send('Content-Type not set yet');
  }

  res.send('Content-Type: ' + contentType);
});

app.listen(3000);

How It Works

  1. Nothing set yet. Early in the handler, Content-Type is usually unset.
  2. get returns empty. Treat falsy as “not present.”
  3. return after send. Avoids falling through to a second response.
  4. Official Content-Type example: after something like res.type('txt'), res.get('Content-Type') can return text/plain.

Runtime Support

res.get() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the finished headers; they do not call this method.

✓ Server · Express 4 & 5

res.get()

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 · Express 4 supported
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
res.get() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Pair res.set with res.get to verify outgoing headers.

Frequently Asked Questions

It returns the current value of an outgoing response header by name. The field match is case-insensitive.
req.get() reads incoming request headers from the client. res.get() reads headers you have set on the response about to be sent.
You typically get undefined. Always treat a missing header as a possible result.
No. res.get('Content-Type') and res.get('content-type') refer to the same field.
After setting a header with res.set(), res.type(), or a helper that sets headers — and before the response is finished.

Next: res.headersSent

Check whether headers have already been flushed to the client.

res.headersSent 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