title: Can't assign a value to a global variable from within a function in NodeJS
body: <p>I'm making a function that searches through a JSON API using an axios get function and then assigns a string to global variable <code>img</code>.</p>
  <pre><code>var img; //declaring the global variable
      axios.get('https://i8xla88513.execute-api.us-east-1.amazonaws.com/latest/items')
      .then(function (res){
        for(i in res.data){ //This searches through the API
          if(res.data[i].name === imgSearch){ 
            img = res.data[i].image; //This assigns a value to the global function
            break;
          }  
        }
      })
  </code></pre>
  <p>I need to call the <code>img</code> variable later in the script; however, when I do <code>console.log(img)</code> inside the function it shows what I want it to show, but if I do <code>console.log(img)</code> or do anything to call the variable outside the function, it shows up as undefined. What am I doing wrong here, and how do I make this modify the global variable <code>img</code> instead of a local one?</p>