res.append()
Appends a value to an HTTP response header, preserving existing values.
Syntax
res.append(field, value) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
field | string | Yes | The header name. |
value | string | string[] | Yes | The value(s) to add to the header. |
Returns
Response — The response object, for chaining.
Examples
app.get('/', (req, res) => {
res.append('Set-Cookie', 'a=1');
res.append('Set-Cookie', 'b=2');
res.send('ok');
});
Output
Set-Cookie: a=1
Set-Cookie: b=2
app.get('/x', (req, res) => {
res.append('Vary', 'Accept');
res.append('Vary', 'Accept-Encoding');
res.end();
});
Output
Vary: Accept, Accept-Encoding
Notes
Unlike `res.set`, which replaces, `res.append` adds another value -
important for multi-value headers like `Set-Cookie`, `Vary`, and
`Link`. Calling `res.set` afterward for the same field overwrites
appended values.