Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Node API Data Not Being Stored In Array

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());
        })
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!