Error AtlasError Documentation and Resolution

Node.js tried to set HTTP headers after they were already sent

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

Node.js rejected an HTTP response change because the headers had already been written, which usually means the handler responded more than once or wrote too early.

ERR_HTTP_HEADERS_SENThttp
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  • The handler sends more than one response for the same request.
  • Headers are modified after the body has already started streaming.
  • Async control flow falls through and writes a second response path.
  1. Make sure each request path returns immediately after sending a response.
  2. Set headers before writing response data or calling methods that flush headers.
  3. Audit async branches and error handlers for duplicate response writes.
Node.js Errors: ERR_HTTP_HEADERS_SENT
Node.js ERR_HTTP_HEADERS_SENT: causes and fixes | Error Atlas