I am making multiple api calls and I want to store the data received in an array, but when I log the array at the end, it returns empty value (or just what the array was initialized with). The data also isn't written to my file.
for(const org of orgs){
axios.get(prod + getAllAppsInOrg + org)
.then((res1) => {
let collectedData = ["Org,Space,ServerName,AppName,Instances,Memory,DiskQuota"];
for(const app of [res1.data[0]]){
//res1.data.forEach( async (app, index) => {
const formData = new URLSearchParams({
orgName: org,
space: app.spaceName.replace(" ", ""),
appName: app.appName
});
axios.post(prod + getAppInfo, formData)
.then((res2) => {
for(const dp of res2.data){
//res2.data.forEach( async (dp) => {
let datapoint = "";
datapoint += org + ",";
datapoint += dp.space + ",";
datapoint += dp.serverName + ",";
datapoint += app.appName + ",";
datapoint += dp.instances + ",";
datapoint += dp.memory + ",";
datapoint += dp.disk_quota;
collectedData.push("\n", datapoint);
}
})
}
console.log(collectedData);
//fs.writeFileSync(__dirname + "/data/" + org + "_prod.csv", collectedData.toString());
})
}