How to determine if the Node.js server response is stopped?

How to determine if a .HttpResponse server is stopped without listening to "end" or "close" events?

What I'm trying to achieve looks something like this:

http.createServer(function (request, response) { var foo; // my event emitting object // ... something compilated happens here ... foo.onSomeEvent(function () { if (response.hasEnded) { // do something } }); }); 
+6
source share
1 answer

You can check the finished property on the response object:

 if (res.finished) { ... } 

(I never used it myself, so I'm not sure if there are any potential problems that should be considered when using it)

+8
source

Source: https://habr.com/ru/post/956073/


All Articles