Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141836

How I can send my axios response to a variable with node.js

$
0
0

In fact, I begin with node.js. And i don't know how to pass the response to a variable. I don't want to make my code in my "response".. I try a lot of things but nothing is working.. I know is a simple question.. but it's not working

const axios = require('axios');
var test = null
function getLeagues () {
  axios.get('https://api-football-v1.p.rapidapi.com/v2/fixtures/league/525?timezone=Europe/Paris', {
   headers: {
    'X-RapidAPI-Key': '<my-api-key>'
   }
  })
  .then(response => {

    test = response.data.api.fixtures

    return response.data.api.fixtures
  })
  .catch(error => {
    console.log(error);
  });
}

console.log(test)


Viewing all articles
Browse latest Browse all 141836

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>