title: How can I use a variable outside an async function in Node.js?
body: <p>I am trying to use the variable <code>bida</code> elsewhere in my code. For example, when I try to create the variable <code>mida</code>. Is there a way to do that without nesting everything inside the <code>getFX()</code> function? I understand it's an async function issue but how can I get around it?</p>
  <pre><code>const fetch = require(&quot;node-fetch&quot;);
  
  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);
  </code></pre>