Express.js res.append() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Response

Definition

res.append() adds a value to an HTTP response header. If the header is not set yet, Express creates it. If it already has values, the new value is added — nothing already set is removed.

Use it for multi-value headers such as Link, Set-Cookie, or Warning. To replace a header completely, use res.set() instead. Call it before you send the body with res.send() or similar.

Syntax

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

Express
res.append(field, value)
res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
res.append('Warning', '199 Miscellaneous warning');
CallWhat it does
res.append(field, value)Primary signature.
res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);Related call form.
res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');Related call form.
res.append('Warning', '199 Miscellaneous warning');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.append(field, value)
res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
res.append('Warning', '199 Miscellaneous warning');

Parameters

ParameterDescription
fieldRequired. HTTP response header name to append to (for example Link or Set-Cookie).
valueRequired. Value or list of values to append. Missing header → Express creates it with these values.

Return Value

res.append() returns res for chaining. It adds a header value without wiping prior values for that field (until a later res.set replaces them).

Express
res.append('Set-Cookie', 'a=1')
  .append('Set-Cookie', 'b=2')
  .status(200)
  .end();

Express.js Examples

Example 3 — Order Matters with set and append

Show why a later res.set() erases values you already appended.

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

app.get('/order', (req, res) => {
  res.append('Warning', '199 - "old value"');
  res.set('Warning', '299 - "new value"'); // resets earlier append
  res.send('Check Warning header');
});

app.listen(3000);

How It Works

  1. Append stores the first warning. Header becomes 199 - "old value".
  2. Set replaces the whole field. Official docs: calling res.set() after res.append() resets the previously set value.
  3. Only the set value remains. Clients never see the appended 199 line.
  4. Safe order: set once if you need a base value, then append extras — never set again for that field.

Runtime Support

res.append() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not call it — they only receive the headers your server sends.

✓ Server · Express 4.11+ & 5

res.append()

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.11+ for append
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
res.append() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It appends one or more values to an HTTP response header. If the header is missing, Express creates it. Existing values stay; new ones are added.
res.set() replaces the header value. res.append() keeps what is already there and adds another value. Prefer append for multi-value headers such as Set-Cookie or Link.
Yes. Pass a string or an array of strings. Express appends each array item for that header field.
res.set() resets that header and drops the values you appended earlier. Append after set, or avoid set for the same field once you have started appending.
It was added in Express 4.11.0 and is available in Express 4 and Express 5. It is not deprecated.

Next: res.attachment()

Mark a response as a file download with Content-Disposition.

res.attachment() 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