req.get()

Returns the value of a request header by name, case-insensitively.

Since Express 4 Spec ↗

Syntax

req.get(field)

Parameters

NameTypeRequiredDescription
field string Yes The header name to read (case-insensitive).

Returns

string | undefined — The header value, or undefined if absent.

Examples

app.get('/ct', (req, res) => {
  res.send(req.get('Content-Type') ?? 'none');
});
Output
$ curl -H 'Content-Type: application/json' localhost:3000/ct
application/json
app.use((req, res, next) => {
  const token = req.get('Authorization')?.replace('Bearer ', '');
  req.token = token;
  next();
});

Notes

Case-insensitive, so `req.get('content-type')` and `req.get('Content-Type')` are equivalent. `req.header()` is an alias. `Referer` and `Referrer` are treated as the same field.

See also