Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download file with Node
// download: download the url to string
utl.download = function(url, cb){
var options = require('url').parse(url),
httpx = url.startsWith(url, 'https:') ? https : http,
data = "",
req = httpx.request(options, function(res){
res.setEncoding("utf8")
res.on("data", function(chunk){
return data += chunk;
})
return res.on("end", function(){
return cb(null, data, url);
})
})
return req.end()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.