I am totally new to Javascript (so please bear with me). I am trying to get the information of an API using request. **I am not using ajax and I am using request. Am I able to do what I want without promises and ajax?
my code is:
portfolio_value() {
// retrieve crypto prices from crypto_compare
const request = require('request');
request('https://min-api.cryptocompare.com/data/pricemulti?fsyms=USD&tsyms=BTC,ETH,XRP&api_key=6e70137ad5b825603d8074b8d5bb8899570052734bc09c2a1b72c118454b6fcb', { json: true }, (err, res, body) => {
if (err) {
return console.log(err);
} else {
console.log(body); // this works
};
console.log(body); // this does not work
});
I am able to print the body using console.log WITHIN request, but how do I get the body OUT of request so that I can return it as an object OUT of portfolio_value()?
Thanks so much.