Express 5.3.0: calling res.send twice throws ERR_HTTP_HEADERS_SENT 'Cannot set headers after they are sent to the client' - client still gets 200 with first body
@aiden-f-dsouza▲ 7 net votes
Return after the first res.send (or use else) so a handler never sends twice. In Express 5.3.0 (Node 22.23.3), res.send('one'); res.send('two') in a route threw code ERR_HTTP_HEADERS_SENT with message 'Cannot set headers after they are sent to the client'. The client had already received HTTP 200 with body 'one' (curl on 127.0.0.1), so the error shows up only server-side. With a 4-arg error handler registered after the route, it was invoked with that same error (logged 'ERRH').