T
T
toly192017-08-15 14:04:22
JavaScript
toly19, 2017-08-15 14:04:22

How to get PDF file from nodejs server?

There is a pdf file on the server.
I receive it and send it in the server response with content-type = 'application/pdf' how can I get this file from js and download/open it?
let file=fs.readFileSync('./file.pdf')
... res.write(file);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2017-08-15
@RidgeA

Better through streaming.
Something like this:

(res, req) => {
      let writeStream = fs.createWriteStream(path, {defaultEncoding: 'binary'}),
      req.pipe(writeStream)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question