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

Express.js · Module

res.append

res.append() adds a value or values to an HTTP response header, creating the header when necessary. It returns the response object and supports string or array values.

How it works

res.append() adds one or more values to an HTTP response header. If the header does not exist, Express creates it; the method returns the response object so calls can be chained.

Syntax

res.append(field [, value])

Parameters

NameTypeDescription
fieldStringName of the HTTP response header to append to.
valueString | String[] | undefinedValue or values to append to the header.

Returns

Response

Key points

  • It adds the supplied value to the named HTTP response header.
  • An absent header is created rather than requiring a separate initialization step.
  • Use a string for one value or an array when adding multiple values.
  • The field argument names the HTTP response header that receives the new value.
  • The value argument represents the header content Express should add.

Common mistakes

  • Do not call res.set() afterward if you need to preserve the values appended by this method.

Example: Append response headers

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

app.get('/', (req, res) => {
  res.append('Link', ['</docs>', '</status>']);
  res.append('Warning', '199 Miscellaneous warning');
  res.send('Headers added');
});

app.listen(3000);

Adds multiple response headers before sending the response.

When to use it

Add multiple Link values

A response needs to expose several related URLs under one Link header.

Append Set-Cookie metadata

A route must attach a cookie header before sending its body.

Add optional response metadata

A handler needs to add a warning or other custom header without manually checking whether it exists.

Interview questions

QWhat does res.append() do when the target header does not exist?

res.append() adds the supplied value or values to the named HTTP response header. When the header is absent, Express creates it with the supplied value.

Follow-up: What types can the value have? It can be a string, an array of strings, or undefined.

QWhat are the arguments to res.append()?

The field identifies the response header, while value contains the value or values to append. Express accepts a string or an array for value.

Follow-up: How can several Link values be added? Pass an array containing each Link value.

QWhat does res.append() return, and what related ordering pitfall exists?

The method returns the Response object. This permits continuing response handling or chaining other response methods after appending the header.

Follow-up: What ordering issue must be considered with res.set()? Calling res.set() afterward resets the header value previously established by res.append().

  • res.set()
  • res.get()
  • res.send()
  • res.header()

Source: API Reference - Express.js. Checked 2026-10-15.