I am just trying to make a simple cryptocurrency price ticker and I can't for the life of me figure out how to export a global variable that I set properly.
var btcPrice;
setTimeout(function(){
  axios.get("https://api.cryptonator.com/api/ticker/btc-usd").then((response) => {
    btcPrice = response.data.ticker.price;
    console.log(btcPrice);
});
}, 5000);
setInterval(function(){
  console.log(btcPrice);
}, 10000);
exports.price = btcPrice;
The setInterval shows the price of bitcoin, as it should. But, when I call it in another file, I get undefined as if it's being exported before the setTimeout finds the value. Any ideas how to export the price? Much appreciated!
