In Express.js, res.set() sets HTTP response headers on the outgoing reply. Pass a field name and value, or an object to set several headers at once. It is aliased as res.header().
Set a custom header.X-Request-Id is available to clients and logs.
Chain status..status(200) uses the same res object.
Finish with JSON.res.json also sets Content-Type for JSON.
Headers first. The custom header is applied before the body is written.
Compatibility
Runtime Support
res.set() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the headers on the HTTP response.
✓ Server · Express 4 & 5
res.set()
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.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.set()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 sets one HTTP response header to a value, or several headers at once when you pass an object. It returns res so you can chain other methods.
No. res.header() is an alias of res.set() and behaves the same way.
Before you send the body with res.send(), res.json(), res.end(), and similar methods. After headers are sent, changes are too late.
res.set() replaces the header value. res.append() adds another value. Calling res.set() after res.append() resets what append built.
No. It runs on your Node.js server. Browsers only receive the headers on the HTTP response.