title: how to use async/await with fs.createReadStream in node js
body: <p>I have node js service which reads csv file and and filter records based on parameters provided. I need to wait till file reading is processed.but its not waiting. I tried using async/await and promise but no luck.</p>
  
  <p>How to wait till file is processed and return json response.</p>
  
  <pre><code>app.get('/getEmpInfo/:emailId/:unique_code', async (req,res) =&gt; {
      console.log("req.params.emailId :"+req.params.emailId);
      console.log("req.params.unique_code :"+req.params.unique_code);
      const response = await getEmpDetailsByEmailIdAndUniqueCode(req.params.emailId,req.params.unique_code);
      res.send(response)
  }); 
  
  async function getEmpDetailsByEmailIdAndUniqueCode(emailId,uniqueCode){
      console.log("inside getEmpDetailsByEmailIdAndUniqueCode()::"+emailId+"::"+uniqueCode);
      var fetchData = [];
  
      // try 1
  /*  await fs.createReadStream(investorFileName1)
        .pipe(csv())
        .on('data', (row) =&gt; {
          if(row.unique_code != null &amp;&amp; row.unique_code == uniqueCode &amp;&amp; row.investor_email_id == emailId) {
              fetchData.push(row);
              console.log(row);
          }
        })
        .on('end', () =&gt; {
          console.log('CSV file successfully processed');
          console.log(fetchData);
      }); */
  
    // try 2
      var response = fs.createReadStream(fileName).pipe(csv());
  
      return new Promise(function(resolve,reject){
          response.on('end', () =&gt; resolve(fetchData));
          response.on('error', reject); 
      })
  }
  </code></pre>