Wednesday 18 July 2018

How to get value from a promise used from a module?

Hii!I'm having a problem.I've used Axios to get a data from an external API, Axios basically uses a promise to make a request to other website, then handle the data.It goes in this fashionaxios.get(API_URL) .then((data)=>{code}) .catch((error)=>{more code}) If I want to console.log the received data, from INSIDE the "then" in the axios promise, it shows me the right data fetched from the api.but If I do:let request = ('./request.js') //the code with the axios request would go here let data = request.get(API_url) console.log(data);what I get is "[object promise]" not the data.wrapping the call in async/await is not working, it gives me the same results: [object Promise].What do? (yes, I've already looked in stackOverflow haha)Thanks!

Submitted July 18, 2018 at 04:19PM by NodeNoodle

No comments:

Post a Comment