-1

Newbie in JS.

I want to get the json response from axios requet

const activities = Axios.get("https://api.github.com/events").then(response => response.data);
console.log(activities);

But I do not understand why it is still showing Promise {<pending>} in console.

Anand Undavia
  • 3,493
  • 5
  • 19
  • 33
Raheel
  • 8,716
  • 9
  • 60
  • 102
  • 1
    can you add more code here ? to acheive this you need to learn how promise works or await/async. – Atul Aug 18 '18 at 18:25

1 Answers1

-1

The reason is that Axios.get() returns a promise. You can apply a .then() callback to the Promise to process what was resolved by the promise.

Here is what you can do:

Axios.get("https://api.github.com/events").then(response => {
    const activities = response.data;
    console.log(activities);
});


You can also use newer async/await depending on version of node you are using:

const foo = async () => {
    const response = await Axios.get("https://api.github.com/events");
    const activities = response.data;
    console.log(activities);
}
Anand Undavia
  • 3,493
  • 5
  • 19
  • 33