I've created a promise function that returns error TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
async function DlFile(url, fileName) {
return new Promise ((fulfill, reject) => {
https.get(url, function(res){
const fileStream = fs.createWriteStream(`C:\\Users\\Garingo-PC\\Documents\\${fileName}.pdf`);
res.pipe(fileStream);
fileStream.on("error", reject);
fileStream.on("finish", fulfill({
status: 'ok'
}));
});
});
}
const Main = async () => {
const result = await DlFile(url, filename);
console.log(result); //returns undefined
}
it should return some an object if it finished downloading the file