Skip to content

Instantly share code, notes, and snippets.

@Octalbyte
Last active November 11, 2020 15:06
Show Gist options
  • Save Octalbyte/3826659c20ff3500666383ac7f01d7bb to your computer and use it in GitHub Desktop.
Save Octalbyte/3826659c20ff3500666383ac7f01d7bb to your computer and use it in GitHub Desktop.
download from url nodejs
const fs = require('fs');
const request = require('request');
let download = (url, dest) => {
const file = fs.createWriteStream(dest);
const sendReq = request.get(url);
sendReq.on('response', (response) => {
sendReq.pipe(file);
});
file.on('finish', () => file.close());
sendReq.on('error', (err) => {
throw new Error(err.message)
});
file.on('error', (err) => {
throw new Error(err.message)
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment