title: Get data out of callbacks
body: <p>I am using &quot;pdf-text&quot; module for Node.js to convert a pdf into a string array and then get specific elements out of it. But the problem is, I can only access the data, &quot;chunks&quot;, only when I am inside the callback. I want to store it in some global variable so that I can use it in different files. I have tried storing the elements of the array inside variables while inside the function, but no luck. Here's the code:</p>
  <pre><code>var pdfText = require('pdf-text');
  
  var pathToPdf = &quot;PDF FILE NAME&quot;;
  
  var fs = require('fs');
  var buffer = fs.readFileSync(pathToPdf);
  
  var output;
  
  pdfText(buffer, function(err, chunks){
  
      if (err){
        console.dir(err);
        return;
      }
      console.dir(chunks);
      output = chunks;
  }
  
  console.dir(output);
  </code></pre>
  <p>P.S. I am fairly new to Node.js and JavaScript and help would be appreciated greatly.</p>