title: Storing request body as global variable
body: <p>I have a project that requires the use of requests and is using javascript run by node. I am having trouble storing the body of a request to a global variable so I can access it in other functions. Is there a way to save the response in a global variable? Thanks.</p>
  
  <pre><code>var request = require('request');
  
  var globalBody = "";
  
  var options = {
      url: 'http://www.google.com/',
      headers: {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25'
      }
  }
  request(options, function (error, response, body) {
     if(error != null){
         console.log('error:', error);
     }
     if(response.statusCode != 200){
         console.log('statusCode:', response &amp;&amp; response.statusCode);
     }else{
         globalBody = body;
     }
  });
  
  
  console.log(globalBody)
  </code></pre>
  
  <p>The last line "console.log(globalBody)" results in "" but I want it to display the body of the request. Is there any way to do this?</p>