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

172
Views
¿Cómo usar axios.all a matriz 2d en Node.js?

Quiero usar una API para conocer el estado de las URL 3*2, y escribí este código fuente pero no funcionó. Tal vez porque esa función newList devuelve funciones de matriz 2d. Y en este código, la función newList funciona dos veces, no sé por qué exactamente.

¿Podría decirme cómo simplificar y hacer que este código funcione normalmente?

API de axios

 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!