
In this example, the user visits /download , and the file named july-report.pdf is downloaded with the name FinalReport2026.pdf . 2. Alternatives: res.sendFile()
However, res.sendFile() can act as a download if you manually set the headers, but res.download() is preferred because it handles the Content-Disposition header for you. 3. Handling Large Files: Node.js Streams node js send file to download
Never trust the user input for file paths. A common vulnerability is Path Traversal (e.g., download?file=../../etc/passwd ). Never use req.query.filename directly. In this example, the user visits /download ,