Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
Return data from axios.all in nodejs

I am trying to implement a function that gets the data from two endpoints using axios.all. The function is the following:

    const items = async () => {
let promisesTest = []
let one = "https://api.storyblok.com/v1/cdn/stories/health?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"
let two = "https://api.storyblok.com/v1/cdn/stories/vue?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"

let miArray = []

promisesTest.push(axios.get(one));
promisesTest.push(axios.get(two));

let apiResponse = []

miArray = await axios.all(promisesTest).then(axios.spread((...responses) => {
    for (let i = 0; i < responses.length; i++) {
        apiResponse.push(responses[i].data)
    }
    return apiResponse
}))
console.log('mi array', miArray)
return miArray
    }

I can correctly see the data in the variable "myArray" but when I invoke the function I cannot visualize said data and what I see when doing console.log (items) is Promise {}

Could you guide me to correctly obtain the data returned by the items function? From already thank you very much

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const axios = require('axios')
const items = async () => {
    let promisesTest = []
    let one = "https://api.storyblok.com/v1/cdn/stories/health?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"
    let two = "https://api.storyblok.com/v1/cdn/stories/vue?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"
    
    let miArray = []
    
    promisesTest.push(axios.get(one));
    promisesTest.push(axios.get(two));
    
    let apiResponse = []
    
    miArray = await axios.all(promisesTest).then(axios.spread((...responses) => {
        for (let i = 0; i < responses.length; i++) {
            apiResponse.push(responses[i].data)
        }
        return apiResponse
    }))
    return miArray;
    }

call function like this

items().then(res => {
    console.log('response', res);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda