Skip to content

Instantly share code, notes, and snippets.

@jonaskahn
Forked from ialpert/nodejs.download.js
Created June 8, 2023 15:38
Show Gist options
  • Save jonaskahn/61da879abb43f9a5dcf815b0f72cdec2 to your computer and use it in GitHub Desktop.
Save jonaskahn/61da879abb43f9a5dcf815b0f72cdec2 to your computer and use it in GitHub Desktop.
Download file using GET and nodejs
function download(url, cb) {
var data = "";
var request = require("http").get(url, function(res) {
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
cb(data);
})
});
request.on('error', function(e) {
console.log("Got error: " + e.message);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment