user11810894
user11810894

Reputation:

Check if res is sent / ended with Express

Using Express, how can I determine the response has been sent / that the response has been completely written to?

app.use((req,res,next) => {

   if(res.ended){
     //
   }

   if(res.finished){
     //
   }

});

how can I tell if res.end() has been called? I am looking for a boolean I can read on res.

Upvotes: 7

Views: 11419

Answers (2)

vitaliydev
vitaliydev

Reputation: 480

Use res.writableEnded (docs).

res.finished is deprecated (see).

Upvotes: 12

tadman
tadman

Reputation: 211580

response.end() will set response.finished if it's been called, as per the documentation.

Upvotes: 4

Related Questions