In Express.js, res.headersSent is a Boolean that tells you whether the app has already sent HTTP headers for this response. It is false before the first flush, and true afterward.
Use it as a guard in callbacks, downloads, and error handlers: if headers are already out, do not call res.send(), res.json(), or change status again. Prefer clear return after a successful send so only one path finishes the response.
Syntax
Read res.headersSent in your Express.js route handler. Start with this line.
GET /boom (nothing sent yet)
→ headersSent === false
→ 500 { "error": "Internal Server Error" }
If a handler already called res.send, then next(err):
→ headersSent === true
→ return next(err) // do not send again
How It Works
Error middleware is last-resort. It may run after a partial response.
Check first. If headers are out, delegate with next(err).
Otherwise send JSON. Safe 500 when the response is still open.
Avoids double-send in apps with streams, timeouts, or multiple async paths.
Compatibility
Runtime Support
res.headersSent is a Boolean on the Express response (Node HTTP response state). It runs on the server (Express 5 needs Node.js 18+). Browsers only see the finished response.
✓ Server · Express 4 & 5
res.headersSent
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 · Express 4 supported
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.headersSentExpress on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Log the flag before and after res.send to see it flip.
Frequently Asked Questions
It is a Boolean property that is true after the app has sent HTTP headers for the response, and false before that.
After methods that flush the response start sending — for example res.send(), res.json(), res.end(), or when a stream/file transfer begins writing headers.
To avoid writing a second response (status, headers, or body) after the first one started — the classic Cannot set headers after they are sent error.
No. It is a property. Read it with res.headersSent; do not call it like a function.
It is a safety check. You should still use clear control flow (return after send) so only one path finishes the response.