Skip to content

Instantly share code, notes, and snippets.

@riston
Created June 6, 2016 13:46
Show Gist options
  • Save riston/40ff0b7caf956091b6c8662b8d5c998d to your computer and use it in GitHub Desktop.
Save riston/40ff0b7caf956091b6c8662b8d5c998d to your computer and use it in GitHub Desktop.
Download file without extra libraries
var http = require("http");
var fs = require("fs");
function getFile(url, saveFile, cb) {
var request = http.get(url, response => {
var write$ = fs.createWriteStream(saveFile);
write$.on("error", cb);
write$.on("finish", () => cb(null));
response.pipe(write$);
});
request.on("error", cb);
}
// Get assets for the
// getFile("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", "./tmp/test.jpg", err => {
// if (err) console.log(err);
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment