title: Get resulting object from fast-csv
body: <p>Suppose I've file named <code>orders.js</code> something like this:</p>
  
  <pre><code>exports.getOrders = function() {
      return {'a': 'b'};
  }
  </code></pre>
  
  <p>and another file named <code>report.js</code> like this:</p>
  
  <pre><code>var Order = require('./src/orders');
  
  console.log(Order.getOrders());
  </code></pre>
  
  <p>This will print <code>{'a' : 'b'}</code> and I'm happy. Now I want to make things more complicated, since I need to read data from a CSV (using <a href="https://www.npmjs.com/package/fast-csv" rel="nofollow noreferrer">fast-csv</a> node package), so I modified the <code>orders.js</code>:</p>
  
  <pre><code>var csv = require('fast-csv');
  
  exports.getOrders = function(clientId) {
  
      var orders = [];
  
      csv
      .fromPath("./data/orders.csv", {headers: true, delimiter:';'})
      .on("data", function(data) {
          orders.push({'price' : data.price});
          }
      })
      .on("end", function(){
          console.log(orders) // THIS WILL PRINT THE CORRECT ARRAY 
          return orders;
      });
  
      console.log(orders); // THIS WILL PRINT AN EMPTY ARRAY
      return orders;
  }
  </code></pre>
  
  <p>How can I return the correct array when <code>Order.getOrders()</code> is invoked in <code>report.js</code>?</p>