I am working with the CoinMarketCap API and have managed to setup and get server response and am getting the values that I need using the following code
request('GET','https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?CMC_PRO_API_KEY=' + apikey.key + '&symbol=BTC,LTC').then((r1) => {
var x1 = JSON.parse(r1.target.responseText);
console.log(x1);
var json = {
BTC: x1.data.BTC.quote.USD.price,
LTC: x1.data.LTC.quote.USD.price,
}
console.log(json.BTC, json.LTC);
}).catch(err => {
console.log(err);
})
Is there a way that I can refer me 'var json' outside the function or in any other file, if not is there any other way I could get the same values without using this method of linking to the server which would allow me to make these public variables
I cannot by default make it a public variable as to when I do so x1
will not be found and making x1
public the r1
would not be found
Hope the question made sense, I am fairly new to this stuff