I am trying to use the variable bida
elsewhere in my code. For example, when I try to create the variable mida
. Is there a way to do that without nesting everything inside the getFX()
function? I understand it's an async function issue but how can I get around it?
const fetch = require("node-fetch");
async function getFX() {
let bida;
try {
var req = await fetch('https://economia.awesomeapi.com.br/all/USD-BRL');
var response = await req.json()
bida = await response.USD.bid;
aska = await response.USD.ask;
console.log(bida, aska)
} catch (e) {
// handle error
console.error(e)
}
}
getFX()
var mida = bida + 1;
console.log (mida);