1 const request = require('request'), 2 fs = require('fs'), 3 path = require('path'); 4 5 6 const image_url = 'http://animalonline.info/wp-content/uploads/2015/01000/white-cat-9kspvw8g.jpg', 7 basename = path.basename(image_url); 8 9 10 request 11 .get(image_url, {timeout: 10000}) 12 .on('response', function(response) { 13 if (response.statusCode !== 200 ) { 14 console.log(`err info ${response.statusCode}`); 15 } 16 }) 17 .on('error', function(err) { 18 console.log(err) 19 }) 20 .pipe(fs.createWriteStream(`${basename}`));