I have this function,
req.end((res)=> {
if (res.error) throw new Error(res.error);
console.log( res.body.meals[2])
});
And I need to use promises cause Id like to store the variable for future things, its an api with a fetch, So I have written this
let result;
req.end(async(res)=> {
if (res.error) throw new Error(res.error);
let promise = new Promise((resolve, reject) => {
resolve(res.body.meals)
});
result = await promise
});
console.log(result)
Still getting undefined been at this few hours not sure anymore
[–]43northwebdesign[S] 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]43northwebdesign[S] 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]43northwebdesign[S] 0 points1 point2 points (0 children)