Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
627 B
2
Indexable
Never
const request = require("request");
const fs = require("fs");

request.post('http://localhost:3050/api/packing/pdf?type=stream', {
    auth: {
        bearer: '...'
    },
    json: {
        ...
    },
})
    .on('error', function (err) {
        // do something with errors
    })
    .on('response', function (response) {
        // do something with the response
    })
    .on('complete', function () {
        // do something when complete, such as cleanup
        console.log("File retrieved!");
    })
    .pipe(fs.createWriteStream('test.pdf')); // Magic line: Pipe the response directly to a file