I would like to retrieve binary data from an https request.
I found a similar question that uses the request method, Getting binary content in Node
You need to set encoding to response, not request:
req = https.request(options, function(res) {
res.setEncoding('binary');
var data = [ ];
res.on('data', function(chunk) {
data.push(chunk);
});
res.on('end', function() {
var binary = Buffer.concat(data);
// binary is your data
});
res.on('error', function(err) {
console.log("Error during HTTP request");
console.log(err.message);
});
});
Here is useful answer: Writing image to local server