Created
August 4, 2022 05:25
-
-
Save crmuhsin/8e7f7514b75e52ec9da9d9b67c5a28d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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