How to send a pdf file from Node/Express app to the browser

后端 未结 5 2045
悲&欢浪女
悲&欢浪女 2020-12-06 00:06

In my Node/Express app I have the following code, which suppose to read a PDF document from a file, and send it to the browser:

var file = fs.createReadStrea         


        
5条回答
  •  心在旅途
    2020-12-06 00:54

    Here's the easiest way:

    app.get('/', (req, res) => res.download('./file.pdf'))
    

    If this gives you trouble. Check the Express.js version or any middlewares that might be necessary.

    Cheers

提交回复
热议问题