title: Prompt a download of PDF with Node.js
body: <p>I am trying to prompt a download of a PDF generated on the server using Node.js. Currently I can save it to the server but not force a download.</p>
  
  <p>I am using npm <code>html-pdf</code> and currently it is saving to the server with this code.</p>
  
  <pre><code>  pdf.create(htmlbody).toStream(function(err, stream){
      console.log(stream);
  
      if (err) return next(err);
  
      stream.pipe(fs.createWriteStream('./foo.pdf'));
  
      res.status(200);
      res.send('Success');
    });
  </code></pre>
  
  <p>How can I make it force a download?</p>
  
  <p>I tried setting headers like </p>
  
  <pre><code>res.setHeader('content-type', 'application/pdf');
  res.setHeader("Content-Disposition", "attachment; filename="+pdfName+";");
  </code></pre>
  
  <p>I am testing on localhost but I don't presume this to be the issue.</p>