ERR_HTTP_HEADERS_SENT 🟩 Node.js

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

  1. return res.status(400).json(...)
  2. Ensure each code path responds once
  3. Check res.headersSent before responding in error handlers

Detailed fix by platform

Node.js

  1. javascript
    if (!user) return res.status(404).json({ error: 'not found' });
    res.json(user);

How to diagnose

  1. Paths — Can two code paths both respond?
  2. 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.