ERR_HTTP_HEADERS_SENT Node.js Origin: Application & API Last updated 12 Oct 2026

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.

Exact message you may see Cannot set headers after they are sent to the client
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 not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

DEP0005 — DeprecationWarning: Buffer() is deprecated due to security and usability issues (DEP0005) (Node.js)DEP0005Headers already sent — Warning: Cannot modify header information - headers already sent (PHP)Headers already sentMODULE_NOT_FOUND — Error: Cannot find module 'x' (MODULE_NOT_FOUND) (Node.js)MODULE_NOT_FOUNDpath-to-regexp — TypeError: Missing parameter name at 1 (path-to-regexp) (Node.js)path-to-regexpreq.body undefined — Express: req.body is undefined / {} (body parser missing) (Node.js)req.body undefinedRouter.use middleware — TypeError: Router.use() requires a middleware function but got a Object (Node.js)Router.use middlewareSyntaxError import — SyntaxError: Cannot use import statement outside a module (Node.js)SyntaxError importERR_HTTP_…

Explore the map of this error Full error map →

🧠 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.