DEV Community

ERROR: Cannot set headers after they are sent to client!!!

Himanshupal0001 on June 21, 2022

UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set Headers after they sent to the client If you encounter this ...
Collapse
 
tqbit profile image
tq-bit • Edited

Or you could try and call res.json(data) after the loop (return may lead to undesired behaviour in this case).

This particular error is often caused whenever you try to send a second response after the first one.

Collapse
 
himanshupal0001 profile image
Himanshupal0001

Thanks for the suggestion.