0
I am trying to pick up the answer of an API, within the function body receives the JSON but outside the function the value is set to Undefined
async function getJSON(){
var options = {
url: "https://economia.awesomeapi.com.br/json/all",
method: 'GET'
}
request(options, function(error, response, body){
console.log(JSON.parse(body))
return JSON.parse(body)
});
};
var cota = getJSON();
console.log(cota)
on the console I have the following exits:
Promise { undefined }
{
USD: {
code: 'USD',
codein: 'BRL',
name: 'Dólar Comercial',
high: '5.1951',
low: '5.101',
varBid: '0.0953',
pctChange: '1.87',
bid: '5.1935',
ask: '5.1966',
timestamp: '1585601996',
create_date: '2020-03-30 18:00:00'
}...
it works now, but how do I export what the quota has stored to another part of the code? I can only use the quota in the console.log
– Lucas Fellipe Mondini Pereira