Express.js req.get() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.get(field) returns the value of a named HTTP request header. The name match is case-insensitive, so Content-Type and content-type both work. Missing headers return undefined.

Special case from the official docs: Referrer and Referer are interchangeable. The method is also aliased as req.header(field). It runs on the server via the request object.

Syntax

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

Express
req.get(field)
req.header(field)   // alias
CallWhat it does
req.get(field)Primary signature.
req.header(field) // aliasRelated 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.get(field)
req.header(field)   // alias

Parameters

ParameterDescription
fieldRequired. Header name to read (case-insensitive). Referrer and Referer are treated as the same field.
StringRequired. Header is present (may include parameters, for example text/plain; charset=utf-8)
undefinedRequired. Header is missing

Return Value

req.get(name) (alias req.header) returns the request header value as a string, or undefined if that header is absent.

Express
const auth = req.get('Authorization');
const type = req.get('Content-Type'); // may include ; charset=...

Express.js Examples

Example 1 — Read Content-Type Either Way

Same result for mixed-case names — matches the official docs example.

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

app.post('/echo-type', (req, res) => {
  // Content-Type: text/plain
  console.log(req.get('Content-Type')); // 'text/plain'
  console.log(req.get('content-type')); // 'text/plain'
  console.log(req.get('Something'));    // undefined

  res.json({
    type: req.get('Content-Type') || null
  });
});

app.listen(3000);

How It Works

  1. Pass any casing. Content-Type and content-type resolve to the same header.
  2. Get the raw string. You receive the full field value as sent (here text/plain).
  3. Missing → undefined. Something was never sent, so the lookup is empty.
  4. Respond safely. Use || null (or a default) when JSON-encoding optional headers.

Example 2 — Require an Authorization Header

Reject requests that omit credentials before running protected logic.

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

app.get('/secure', (req, res) => {
  const auth = req.get('Authorization');
  if (!auth) {
    return res.status(401).send('Missing Authorization header');
  }
  if (!auth.startsWith('Bearer ')) {
    return res.status(401).send('Expected Bearer token');
  }
  res.send('Authorization header received');
});

app.listen(3000);

How It Works

  1. Read the header. req.get('Authorization') returns the full value or undefined.
  2. Handle missing first. No header → 401 immediately.
  3. Check the shape. A simple Bearer prefix guard rejects obviously wrong formats.
  4. Then verify the token. Real apps would validate the token next; this demo only shows header access.

Example 3 — Referer and Referrer Are Interchangeable

Either spelling works with req.get(), as documented by Express.

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

app.get('/from', (req, res) => {
  const viaReferrer = req.get('Referrer');
  const viaReferer = req.get('Referer');

  res.json({
    referrer: viaReferrer || null,
    referer: viaReferer || null,
    same: viaReferrer === viaReferer
  });
});

app.listen(3000);

How It Works

  1. HTTP uses Referer. The historic misspelling is the real header name on the wire.
  2. Express accepts both. req.get('Referrer') and req.get('Referer') read the same field.
  3. Values match. When the header is present, both calls return the same string.
  4. Still optional. Many clients omit it for privacy — always allow undefined.

Runtime Support

req.get() is an Express.js request method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send headers; they do not call req.get().

✓ Server · Express 4 & 5

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

Bottom line: Study and run these examples with Node.js and the express package. Use req.get(name) whenever you need one request header.

Frequently Asked Questions

It returns the value of a named HTTP request header. Matching is case-insensitive. Missing headers return undefined.
No. req.header(field) is an alias of req.get(field). Prefer one style and stick to it.
Yes for req.get(). Express treats Referrer and Referer as interchangeable spellings of the same header.
req.get returns the raw header string. req.is() checks whether that Content-Type matches a type you care about (json, html, and so on).
No. Clients control most request headers. Validate Authorization and custom headers before using them for security decisions.

Next: req.host

Read the hostname derived from the Host header (and trust proxy rules).

req.host 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