Skip to content

Instantly share code, notes, and snippets.

@crmuhsin
Created August 4, 2022 05:25
Show Gist options
  • Save crmuhsin/8e7f7514b75e52ec9da9d9b67c5a28d8 to your computer and use it in GitHub Desktop.
Save crmuhsin/8e7f7514b75e52ec9da9d9b67c5a28d8 to your computer and use it in GitHub Desktop.
import fs from 'fs';
import fetch from "node-fetch";
async function downloadFile(url, savePath) {
let res = await fetch(url)
return new Promise((resolve, reject) => {
const dest = fs.createWriteStream(savePath);
res.body.pipe(dest);
res.body.on("end", () => resolve(savePath));
dest.on("error", reject);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment