title: Storing nodejs fs.readfile's result in a variable and pass to global variable
body: <p>I'm wondering if it's possible to pass the contents of fs.readfile out of the scope of the readfile method and store it in a variable similar to.</p>
  <pre><code>var a;
  
  function b () {
      var c = &quot;from scope of b&quot;;
      a = c;
  }
  b();
  </code></pre>
  <p>Then I can console.log(a); or pass it to another variable.</p>
  <p>My question:</p>
  <p>Is there a way to do this with fs.readFile so that the contents (data) get passed to the global variable global_data.</p>
  <pre><code>var fs = require(&quot;fs&quot;);
  
  var global_data;
  
  fs.readFile(&quot;example.txt&quot;, &quot;UTF8&quot;, function(err, data) {
      if (err) { throw err };
      global_data = data;
  });
  
  console.log(global_data);  // undefined
  </code></pre>