res.append() adds a value to a response header. If the header doesn't exist yet, Express
creates it.
Syntax
res.append(field [, value])
Example
const express = require("express");
const app = express();
const PORT = 4800;
app.get("/", (req, res) => {
res.append("X-Powered-By", "PixelMart-API");
res.append("Set-Cookie", "seen=true");
res.append("Set-Cookie", "region=bd");
res.send("Headers appended");
});
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
Calling res.append() twice on the same header (like Set-Cookie) accumulates values
instead of overwriting them.
Use cases
- Adding multiple values to the same response header.
- Building
Linkheaders for pagination or related resources. - Attaching custom metadata headers dynamically.