https://github.com/infoforcefeed/filth-bot/blob/main/src/telegram-bot.ts#L142 js var download = function(url, dest, cb) { return new Promise((res, rej) => { var file = fs.createWriteStream(dest); https.get(url, function(response) { response.pipe(file); file.on('finish', () => { console.log('downloaded image.'); file.close(); cb(); }); }); }