how to download a file with Nodejs(without using third-party libraries)用node下载文件

创建HTTP GET请求并将其管理response到可写文件流中:

var http = require('http');
var fs = require('fs');

var file = fs.createWriteStream("file.jpg");
var request = http.get("http://blog.mongolab.com/wp-content/uploads/2014/01/data_extents1-1024x430.png", function(response) {
  response.pipe(file);
});

  

原文地址:https://www.cnblogs.com/yu-hailong/p/7651035.html