Skip to content

Instantly share code, notes, and snippets.

@imchao9
Created June 20, 2016 09:47
Show Gist options
  • Select an option

  • Save imchao9/a67a49e40e7cf55ac6d170696f5d12e9 to your computer and use it in GitHub Desktop.

Select an option

Save imchao9/a67a49e40e7cf55ac6d170696f5d12e9 to your computer and use it in GitHub Desktop.
nodejs下载文件
function downloadFile(url) {
var httpClient = url.slice(0,5) === "https"? https:http;
httpClient.get(url,function(response) {
var RegFileName = new RegExp();
RegFileName.compile(".*%2F(.*?)$");
var fileName = RegFileName.exec(url)[1];
console.log(fileName);
if(fileName) {
var writer = fs.createWriteStream(resPath+fileName);
response.pipe(writer);
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment