import { createWriteStream } from "fs" ; import { promisify } from "util" ; import { pipeline } from "stream" ; import fetch from "node-fetch" ; const streamPipeline = promisify ( pipeline ) ; param { String } URL param { String } path export default async function download ( URL , path ) { try { const response = await fetch ( URL ) ; if ( ! response . ok ) { throw new Error ( `unexpected response ${ response . statusText }` ) ; } await streamPipeline ( response . body , createWriteStream ( path ) ) ; } catch ( e ) { console . log ( `[download]: Error while downloading ${ URL }` , e ) ; } }