javascript - How to detect client closing connection during piping stream over http in node? -


i stream data server client in expressjs (nodejs) application.

i this;

// let contenttype , filename correctly defined in context  function(req,res){     res.setheader('content-type',contenttype);     res.setheader('content-disposition','attachment; filename='+filename);     require('fs').createreadstream('/path/file').pipe(res); } 

i want know when client fails download file, don't how proceed.

listen close event on response object. emitted when connection client closed prematurely refreshing page or closing tab.

require('fs').createreadstream('/path/file').pipe(res).on('close',function(){    //do stuff closed connection }) 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -