title: How to access value returned by a callback function in outer scope?
body: <p>I am having troubles accessing values from within a callback function in parent/outer scope. Basically I want to access the data that the following <code>s3.getObject()</code> function fetches and use it in outer scope (last line).</p>
  
  <p>I have the following javascript code to fetch some data from AWS:</p>
  
  <pre><code>const Papa = require('papaparse'); 
  const AWS = require('aws-sdk')
  
  AWS.config.update({
      //ids
  })
  
  const s3 = new AWS.S3()
  
  
  /* actual parameters should go here */
  const params = {
    Bucket: "test-ashish-2019", 
    Key: "dummy.csv"
  };
  
  const parseOptions = {
    header: true,
    dynamicTyping: true
  }
  
  s3.getObject(params, function(err, data) {
  if (err)  console.log(err, err.stack);
  //   else {console.log(data)};
  else {
      const csv = data.Body.toString('utf-8'); 
      const headers = 'id,start,end,count';
      const parsed = Papa.parse(headers + '\n' + csv, parseOptions);
      var csvdata = parsed.data;
      console.log(csvdata); //this is working as expected
      }
  
  });
  
  console.log(csvdata); //not working as expected
  </code></pre>
  
  <p>How do I make the last line work?</p>