Node.js download PDF file from REST Api

I want to download pdf file from the server with REST API. This is has to be done inside my node.js application

This can be done easily with axios .

First you have to send the get request to server with responseType: "stream"

If you need to do authentication you can pass the acessToken with following line

axios.defaults.headers.common['Authorization'] = 'Bearer '+arg.acessToken

Once you get the response from the server you can use response.data.pipe to create the stream to write the file contents. So you can use the fs.createWriteStream("data.pdf") to achieve that