Web globals

new Headers()

Constructs a normalized HTTP header collection. Do not copy all inbound headers to an outbound request without an allowlist. Tested on Node.js 22.16.0. Example output (one line per entry): ["lab-7 false"].

Formal Syntax & Structure

nodejs syntaxnodejs
new Headers([init])

Parameters & Attributes

NameTypeDescription
initobject | ArrayInitial headers.

Return Value

Headers

Header collection.

Working Example

Example Snippetnodejs
const h = new Headers({ 'X-Request-ID': 'lab-7' });console.log(h.get('x-request-id'), h.has('authorization'));
Node.js Reference