router.get("/fixtures/generate", (_, res) => {
Promise.all([
// EPL BELOW
axios({
"method": "GET",
"url": "https://api-football-v1.p.rapidapi.com/v2/fixtures/league/524/last/10",
"headers": {
"content-type": "application/octet-stream",
"x-rapidapi-host": "api-football-v1.p.rapidapi.com",
"x-rapidapi-key": "6b5ca05e55mshb0e3216e47a54acp1192aajsna0ef871f4f24"
}, "params": {
"timezone": "Europe/London"
}
}),
// LA LIGA BELOW
axios({
"method": "GET",
"url": "https://api-football-v1.p.rapidapi.com/v2/fixtures/league/775/last/10",
"headers": {
"content-type": "application/octet-stream",
"x-rapidapi-host": "api-football-v1.p.rapidapi.com",
"x-rapidapi-key": "6b5ca05e55mshb0e3216e47a54acp1192aajsna0ef871f4f24"
}, "params": {
"timezone": "Europe/London"
}
}),
// CL BELOW
axios({
"method": "GET",
"url": "https://api-football-v1.p.rapidapi.com/v2/fixtures/league/530/last/10",
"headers": {
"content-type": "application/octet-stream",
"x-rapidapi-host": "api-football-v1.p.rapidapi.com",
"x-rapidapi-key": "6b5ca05e55mshb0e3216e47a54acp1192aajsna0ef871f4f24"
}, "params": {
"timezone": "Europe/London"
}
})]
.then((response) => {
fs.writeFile(scoresFilePath, JSON.stringify(response.data.api.fixtures), err => {
if (err) return res.status(409).send("File not saved"); // find right error code
return
console.log("scores saved!");
});
})
.catch(err => res.status(400).send("Could not fetch data"))
)
});
I used square brackets to place all my calls in an array and am getting the error: TypeError: [axios(...),axios(...),axios(...)].then is not a function at /Users/Desktop/server/routes/routes.js:62:10 at Layer.handle [as handle_request] (/Users/Desktop/server/node_modules/express/lib/router/layer.js:95:5) at next (/Users/one/Desktop/server/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/Users/one/Desktop/server/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/Users//Desktop/server/node_modules/express/lib/router/layer.js:95:5) at /Users/Desktop/server/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/Users/Desktop/server/node_modules/express/lib/router/index.js:335:12) at next (/Users/Desktop/server/node_modules/express/lib/router/index.js:275:10) at Function.handle (/Users/Desktop/server/node_modules/express/lib/router/index.js:174:3) at router (/Users/Desktop/server/node_modules/express/lib/router/index.js:47:12)
>I am trying to write all the response data into one JSON file with Promise.all