How to load an image from url to buffer in nodejs

My computer develop environment

1
2
node -v  //v8.1.0
npm -v //5.3.0

After http request a image url , I want the buffer for picture storage service

so the code look like:

1
2
3
4
var request = require('request').defaults({encoding: null});
request(url, function (error, response, body) {
//body default is string , but it's buffer type now
});

or

1
2
3
4
5
6
7
8
9
10
var request = require('request');

var requestSettings = {
method: 'GET',
url: url,
encoding: null
};
request(url, function (error, response, body) {
//body default is string , but it's buffer type now
});

Share