I am new to javascript and am trying to fetch data from an API then post it to my own server (localhost).
I get the data using axios below:
async function getNCAA() {
axios
.get(`https://api.the-odds-api.com/v4/sports/${sportKey1}/scores/?daysFrom=1&apiKey=${apiKey}`)
.then((res) => {
console.log(res.data)
console.log("Remaining requests", res.headers["x-requests-remaining"]);
console.log("Used requests", res.headers["x-requests-used"]);
return res.data
})
.catch((error) => {
console.log("Error status", error.response.status);
console.log(error.response.data);
return error
});
}
assign the data
let result = getNCAA();
then try to send it using express:
app.get('/', (req, res) => {
res.send(result);
});
The result returns a Promise object that I don’t know how to access.
I’ve been able to access this data in the past by using a useState but I am not running a React app in this particular case