Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
An Express/Node handler tried to send a second response (or set headers) after one was already sent.
Cannot set headers after they are sent to the client Meaning
Usually a missing return after res.send()/res.json(), calling next() after responding, or both a callback and a promise resolving.
Common causes
- Missing return after res.json() in an if-branch
- Calling next() after sending
- Async code responding twice (callback + catch)
- Middleware sending a response then calling next()
⚡ Quick fix
- return res.status(400).json(...)
- Ensure each code path responds once
- Check res.headersSent before responding in error handlers
Detailed fix by platform
Node.js
- javascript
if (!user) return res.status(404).json({ error: 'not found' }); res.json(user);
How to diagnose
- Paths — Can two code paths both respond?
- Middleware — Does it call next() after sending?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Node.js
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026