title: TypeError: Cannot read property 'then' of undefined on Promise in Express route
body: <p>I have a route in my MEEN app that accepts a file upload, then passes the data to a helper module that parses the file and stores it in an array, once this helper module finishes I want to pass it off to another module that will then process the returned array. for some reason even though I have a return statement at the end of the helper the then method is undefined.</p>
  
  <p>route:</p>
  
  <pre><code>router.route('/tools/sku/reactivate').post(upload.single('csvdata'),function(req,res){
          console.log('handing request over to helper.csv');
          csv.reader(req,res).then(sku.reactivate(data));
      });
  </code></pre>
  
  <p>csv.reader:</p>
  
  <pre><code>var csv = require('csv-parse');
  var multer = require('multer');
  var fs = require('fs');
  
  module.exports.reader = function(req,res){
    //define array for holding csv data in this case skus
      const csvArray = [];
      //max number of columns in csv
      const maxColumns = parseInt(req.body.maxColumns);
      //create an array of column headers to check chunks against so we dont parse headers
      let columnHeader = req.body.moduleTarget.split(',');
      //loopThrough Array to create arrays inside container array for each column
      for(var i = 0; i &lt; maxColumns; i++){
          csvArray.push([]);
      }
      //define filesystem readstream from uploaded file
      let readStream = fs.createReadStream(req.file.path).pipe(csv());
      //push csv data to array ignoring headers to csvArray
      readStream.on('data', function(chunk){
          //get number of keys in the dataChunk
          let chunkLength = Object.keys(chunk).length;
          //check column count on csv if greater than expected throw error
          if(chunk[maxColumns]){
              throw '[ERROR] More columns than expected in CSV, please fix and try again';
          }else{
              //loop through chunk keys and store each one in csvArray by index
              for(var i = 0; i &lt; chunkLength; i++){
                  //if chunk at this index doesnt equal column header and chunk at this index exists push to array
                  if(chunk[i] !== columnHeader[i] &amp;&amp; chunk[i]){
                      csvArray[i].push(chunk[i]);
                  }
              }
          }
      });
      //error handling
      readStream.on('error',function(err){
          console.log('Error while reading file stream '+ err);
          res.json({message:err,errorType:'1'});
      });
      readStream.on('end',function(){
          console.log('finished reading csv returning array back to router to process next middleware');
          return csvArray;
      });
  }
  </code></pre>
  
  <p>i get an error right after the console.log message on the readStream end listener</p>