I'm attempting to save some data returned from my getData() function which is executing some code for an api call. When the function is console.log it logs ' undefined '. Even after calling the await function which to my understanding should mean the asynchronous function should be completed
const options = {
method: 'GET',
url: 'https://api-football-v1.p.rapidapi.com/v3/players/topscorers',
params: {league: '39', season: '2020'},
headers: {
'X-RapidAPI-Key': 'ef7d32ce87msh2696077fbb1cc96p100c3ajsn9a96c91783dc',
'X-RapidAPI-Host': 'api-football-v1.p.rapidapi.com'
}
};
function getData(options) {
axios.request(options).then(function (response) {
return response
}).catch(function (error) {
return error
})
}
await console.log(getData(options))
const [top_scorer_data, top_assists_data] = await Promise.all([
getData(options),
getData(options2)
]).catch(err => {
console.log('err', err);
});
res.render('bundesliga/stats', {
top_scorer_data,
top_assists_data
});