As I continue expanding on express.js this month today I thought I would write about the response download method, which is one of the many methods in express that are part of the standard response object that I might write about more this week. The download response method will send a file as an attachment rather than the content to be displayed, so it does differ a little from the send file response method that would be used as a way to send a file as browser display content, rather than an attachment to be downloaded to a place on a clients local file system.
This download method of the response object of a middleware function is useful if you want to have some kind of path that will work as a way to deliver a file as a download when a link is clicked, or something to that effect. When doing so the user should end up being prompted if they want to download the file, and if it is something they want they can then click to downloaded to a location on there local file system. It is very easy to use, you do not have to worry about setting the proper headers or anything like that it does it all for you so all that has to be done basically is to just call a method in the response object.
Read More