Assuming you are using the express server, use res.download
It downloads the file in the path as a attachment
:
var express = require('express');
var router = express.Router();
router.get('/download', function (req, res, next) {
var filePath = "/Users/meuuser/PDFs"; //caminho do arquivo completo
var fileName = "report.pdf"; // O nome padrão que o browser vai usar pra fazer download
res.download(filePath, fileName);
});
Note: There is res.attachment
, but if you use it, it will set the header Content-Disposition
to "attachment" and this will make the browser understand that it should be seen as an attachment, not a webpage When you use res.download
, it transfers the file as an attachment, then usually browsers will consider downloading the file.
Reference: Express documentation res.download .