IncomingMessage abort event
Your code sets up some event listeners, then sends the response back to the client right away, thereby completing the HTTP request prematurely.
Moving res.send()
inside the event handlers, keeps the connection open until one of those events takes place.
app.put('/', function(req, res) { req.on('close', function() { console.log('closed'); res.send(200); }); req.on('end', function() { console.log('ended'); res.send(200); }); req.on('error', function(err) { console.log(err); res.send(200); });});