I have currently following code:
var request = require('request');
var variable1;
request('https://api.coindesk.com/v1/bpi/currentprice/EUR.json', function (error, response, body){
var btceurpricejson = (body);
var obj = JSON.parse(btceurpricejson);
variable1 = (obj.bpi.EUR.rate_float);
});
function getBTCItemPrice() {
console.log(variable1);
};
getBTCItemPrice();
But it always only outputs undefined
. When I use console.log(variable1);
in the request function, it works. But when I use it like above, in another function, it doesn't work. Even though I use a global variable.
Thank you in advance!