We do something similar to @guptast ...
But we use a form in a modal this regard.
We use PHP and not NodeJS
<form action="../dmxConnect/api/admin_download_csv.php" method="post" id="formcsvdownload" is="dmx-serverconnect-form" dmx-on:success="notifies1.success('Done');formcsvdownload.reset();browser1.goto('../downloads/csv-'+query.id+'-'+randomvaluepickup.value+'.csv');delete_csv.load({});modalDownloadCSV.hide()">
csv-'+query.id+'-'+randomvaluepickup.value+'.csv = is just so we can give this a unique file name as we have seen if you dont then the downloaded csv sometimes dont refresh the data.
So the csv data in our case is maybe about 10 000 records and it works great...
So the form calls the server action... then to goto... gets the file in the folder.... then we have another server connect (no autoload) delete_csv... eg delete_csv.load in the form.
So once the file is downloaded.. the delete_csv is checking if the file is in folder.. and then deletes it...
and the server connect for us
<dmx-serverconnect id="delete_csv" url="../dmxConnect/api/delete_csv.php" noload="noload" dmx-param:id="query.id" dmx-param:randomvaluepickup="randomvaluepickup.value"></dmx-serverconnect>