How to download pdf file from url in node.js?

This will Help.

response.setHeader("Content-Type", "text/pdf");

This Link will help


For those looking to download a PDF server side, which is a bit of a different use case than the OP, here's how I did it using the request npm module:

const fs = require("fs");
const request = require("request-promise-native");

async function downloadPDF(pdfURL, outputFilename) {
    let pdfBuffer = await request.get({uri: pdfURL, encoding: null});
    console.log("Writing downloaded PDF file to " + outputFilename + "...");
    fs.writeFileSync(outputFilename, pdfBuffer);
}

downloadPDF("https://www.ieee.org/content/dam/ieee-org/ieee/web/org/pubs/ecf_faq.pdf", "c:/temp/somePDF.pdf");

Simple solution I used to download pdf in node js is by npm i node-downloader-helper and just add downlaod url:

const { DownloaderHelper } = require('node-downloader-helper');

const download = new DownloaderHelper('url', __dirname);
download.on('end', () => console.log('Download Completed'))
download.start();