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

273
Views
How to use promise object value in global object?

As shown below, there is a function that pulls data from a specific server using a function that uses a promise object called axios.

const getData = async () => {
try {
    const result = await axios.get(
        "https://b2ef45f8-e166-41d7-bd35-9ad159028fbf.mock.pstmn.io/test"
    );

    const products = result.data.products;

    console.log(products);

    console.log(`status:(${result.status}) sucess to connection`);

    const data = JSON.stringify(products);

    return data;
} catch (err) {
    console.error(err);

    console.log("failed to get result.");

    return err;
}

};

console.log(getData());

it is free to use the value inside the function, When I try to get the value by calling that function in global space, the value Promise { } is first printed to the console, followed by the contents of the function above. I understands that this is because promises are asynchronous. However, I have to use this promise value (data variable) in the global context, so I want to know how to use it in the global context.

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!