title: How to get response from unirest nodejs POST call?
body: <p>I have used the following code sample to call a API which returns a access token. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var responsedata = '';
  
  unirest.post('http://sandbox.com/api/getToken')
    .headers({'Content-Type': 'application/x-www-form-urlencoded'})
    .send('apiKey=xewsdw232')
    .send('username=theuser')
    .end(function (response) {
  
      console.log(response.body);
      responsedata = response.body;
      
      
    });
  
  console.log(responsedata);</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p>Response </p>
  </blockquote>
  
  <p><code>{ data: { token: 'JhbGciOiJIUzI1NiJ9',transID:'00582',errorCode: '00',errorMessage: '' } }</code></p>
  
  <p>I do get response which gets logged into the console but unable to assign it to a variable to that I can work with it outside the call function. I am struggling with understanding how callbacks work in javascript.</p>