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

177
Views
How to use axios.all to 2d array in Node.js?

I want to use an api to know status of 3*2 urls, and I wrote this source code but it didn't work. Maybe because that newList function returns 2d array functions so. And in this code, newList function works twice like, I don't know why exactly.

Could you please tell me how to simplify and make work this code normally?

axios api

const axiosInstance = axios.create({ timeout:3000 });
let server = new Array(3)
server[0] = 'http://serverUrl0:'
server[1] = 'http://serverUrl1:'
server[2] = 'http://serverUrl2:'
let postfixA = '12345/?version=0'
let postfixB = '12222/?version=1'
let serverList = createArray(3,2) // make array[3,2]
for (let i =0;i<server.length; i++){
    for(let j=0; j<2 ; j++){
        serverList[i][0] = {url : server[i]+postfixA, result : 200}
        serverList[i][1] = {url : server[i]+postfixB, result : 200}
    }
}

function newList(){
    return serverList.map((valueArray, i )=>{
        return valueArray.map((value, j)=>{
            return axiosInstance.get(
                value.url
            ).catch(function (error){
                console.log(`lnbServers server ${i+1} ${j==0 ? 'A':'B'} Error >>`, error.message)
                value.result = 500
            })
        })
    })
}

try {
    await axios.all(newList())
    
    
    let data = {}
    for(let i=0; i<server.length; i++){
        let keyStr = 'server_'+i
        for(let j=0; j<2; j++){
            keyStr+= j%2==0 ? 'A' : 'B'
            data[keyStr] = serverList[i][j].result
        }
    }
    response.json(data)
    
} catch (err) {
    console.log(err)
    response.sendStatus(500)
}
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!