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

115
Views
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 answers
Answer question

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 Report
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!