Express includes a res.download()
method that works very similarly to the res.sendfile()
method, with only a few differences. The res.download()
method sends a file in the HTTP response as an attachment, which means the Content-Disposition
header is set. The res.download()
method uses the following syntax:
res.download(path, [filename], [callback])
The path
parameter points to the file to send to the client. The filename
parameter can specify a different filename that should be sent in the Content-Disposition
header. The callback function is executed after the file download has completed.