title: Use request module to retrieve JSON and return value
body: <p>I use this <a href="https://github.com/mikeal/request" rel="nofollow"><code>request</code></a> module to make HTTP request in Nodejs</p>
  
  <p>Sample code:</p>
  
  <pre><code>module.exports.getToken = function(){
      var token ;
  
      request(validLoginRequest, function(err,resp,body){
          var json = JSON.parse(JSON.stringify(body));
          console.log("from request(): token=" + json.accesstoken);
          token = json.accesstoken;
      });
  
      console.log("getToken() returns:" + token);
      return token;
  }
  </code></pre>
  
  <p>But the <code>token</code> is always <code>undefined</code>. What did I do wrong?</p>