Skip to content

Instantly share code, notes, and snippets.

@evanmoran
Created October 14, 2013 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanmoran/6978386 to your computer and use it in GitHub Desktop.
Save evanmoran/6978386 to your computer and use it in GitHub Desktop.
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