Found two questions that answered my question. Therefore, obviously, we do not need to use express.static middleware. We just need the file system to download the file :
app.get('/download', function(req, res){ var file = __dirname + '/upload-folder/dramaticpenguin.MOV'; res.download(file);
If we want to stream and then delete , follow these steps:
app.get('/download', function(req, res){ var stream = fs.createReadStream('<filepath>/example.pdf', {bufferSize: 64 * 1024}) stream.pipe(res); var had_error = false; stream.on('error', function(err){ had_error = true; }); stream.on('close', function(){ if (!had_error) fs.unlink('<filepath>/example.pdf'); });
source share