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.
Seen on:
Node.js
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026