0

I am trying to work out where in my code is causing the following error which ends up crashing the system

_http_outgoing.js:536
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:536:11)
    at ServerResponse.header (/home/(APP)/node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/home/(APP)/node_modules/express/lib/response.js:170:12)
    at /home/(APP)/app.js:209:23
    at ChildProcess.exithandler (child_process.js:299:7)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1051:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

I don't mind it throwing the error, but I don't want it crashing my nodejs application. Any suggestions on finding what part of the code could cause this.

  • 1
    The error occurs, because you try to `res.send()` or something like that, when you already returned the request to the client. We would need to see your app.js to help you further, since line 209 of app.js is listed in the stack trace. – Geshode Sep 01 '22 at 03:08
  • you can wrap your code in `try catch` block where the error occurred and then your system won't crash! – Vishal Beep Sep 01 '22 at 03:40
  • Does this answer your question? [Error: Can't set headers after they are sent to the client](https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client) – Youssouf Oumar Sep 01 '22 at 12:39

0 Answers0