Return data from axios.all in nodejs

I am trying to implement a function that gets the data from two endpoints using … Read more 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

Source: JavaSript – Stack Overflow


Categories: NewsTags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *