title: Nodejs Async/Await not working on a file stream function
body: <p>Currently, I am trying to parse a csv file with {Lat, Lng, Mag}. Also, I am creating Polygons to use the magnitude. If the point {Lat, Lng} is in the Polygon, then the Magnitude will be added to the Polygon Magnitude. The function works as described, but the data is computed very slowly and the response does not contain the magnitude calculated. Below is my code:</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  const csv = require('csv-parser')
  const fs = require('fs');
  const { exit } = require('process');
  const { resolveObjectURL } = require('buffer');
  
  
  /*
  Things to parse:
  1.) offense count
  2.) latitude
  3.) longitude
  */
  
  function getPolygons() {
      let Count = 16
      let ParentPolygon = [
          {lat: 30.118713, lng: -95.812735 }, // Top Left
          {lat: 30.118713, lng: -95.034621 }, // Top Right
          {lat: 29.49764, lng:  -95.034621}, // Bottom Right
          {lat: 29.49764, lng: -95.812735 } // Bottom Left
      ]
  
      length = Math.abs(30.11873 - 29.49764)
      width = Math.abs(-95.812735 + 95.034621)
  
      length_cut = length/Math.sqrt(Count)
      width_cut = width/Math.sqrt(Count)
  
      let result = []
      let point = ParentPolygon[0] // Start at top left of Parent Polygon
      for(let j = 0; j &lt; Math.sqrt(Count); j++){
          let FindNewChild = true;
          let FirstChildBottomLeft = {lat: 0, lng: 0}
          for(let i = 0; i &lt; Math.sqrt(Count); i++ ){
              
              let ChildPolygon = [
                  {lat: point.lat, lng: point.lng  }, //Top left
                  {lat: point.lat, lng: point.lng + width_cut}, //Top Right
                  {lat: point.lat - length_cut, lng: point.lng + width_cut},  //Bottom Right
                  {lat: point.lat - length_cut, lng: point.lng} //Bottom Left
              ]
              if(FindNewChild){
                  FirstChildBottomLeft = ChildPolygon[3]
                  FindNewChild = false;
              }
  
              if(i === Math.sqrt(Count) - 1){
                  point = FirstChildBottomLeft
                  FindNewChild = true;
              } else
              {
                  point = ChildPolygon[1]
              }       
  
              result.push({mag: 0, square: ChildPolygon})
          }
  
      }
  
      return result;
  
  
  }
  /*
                      {
                          {
                              magnitude: 0,
                              square: [
                                  {lat: 30, lng: 45},
                                  {lat: 30, lng: 55},
                                  {lat: 40, lng: 45},
                                  {lat: 40, lng: 55}
                              ]
                          },
                          {
                              magnitude: 0,
                              square: {
                                  {lat: 30, lng: 45},
                                  {lat: 30, lng: 55},
                                  {lat: 40, lng: 45},
                                  {lat: 40, lng: 55}
                              }
                          },
                          {
                              magnitude: 0,
                              square: {
                                  {lat: 30, lng: 45},
                                  {lat: 30, lng: 55},
                                  {lat: 40, lng: 45},
                                  {lat: 40, lng: 55}
                              }
                          }
  
  
                      }
  
  
                  */
  
  
  async function getParsedData() {
      let results = await getPolygons();
      let file = '../server/datafiles/NIBRSPublicViewJan-Mar22.csv' // hard coded file &amp; file directory
  
      await fs.createReadStream(file)
          .pipe(csv({mapValues: ({value}) =&gt; parseFloat(value)}))
          .on('data', (data) =&gt; {
              if(data.lat &amp;&amp; data.lng &amp;&amp; data.mag) { // check if a latitude and longitude exist
              
                  let point = ({lng: parseFloat(data.lat), lat: parseFloat(data.lng), mag: parseFloat(data.mag)})
                  results.forEach(polygon =&gt; {
                      let TopLeft = polygon.square[0]
                      let BottomRight = polygon.square[2]
  
                      //Something is wrong with this statement
                      
                      if(point.lat &lt; TopLeft.lat &amp;&amp; point.lng &gt; TopLeft.lng){
                          if(point.lat &gt; BottomRight.lat &amp;&amp; point.lng &lt; BottomRight.lng){
                              //console.log(&quot;Top Left:&quot; + TopLeft.lat + &quot;, &quot; + TopLeft.lng, &quot;Point: &quot;+ point.lat + &quot;, &quot; + point.lng)
                              //console.log(&quot;Bottom Right:&quot; + BottomRight.lat + &quot;, &quot; + BottomRight.lng, &quot;Point: &quot;+ point.lat + &quot;, &quot; + point.lng)
                              //console.log(&quot;point Magnitude: &quot;, point.mag, &quot;Polygon mag: &quot;, polygon.mag)
  
                              polygon.mag += point.mag
                          } 
                      }
                  })
  
              }
          })
          .on('end', () =&gt; {
          console.log(&quot;What should go to Front-end&quot;, results); // check to see if the results are correct
         
      }); 
  
      return results;
  }
  
  router.get('/', async (req, res) =&gt; {
      getParsedData()
      .then(results =&gt; {
          console.log(&quot;To Front-end&quot; , results)
          res.json(results)
      })
  })
  
  module.exports = router;
  </code></pre>
  <p>EDIT: The result should look like this:</p>
  <pre><code>[
    { mag: 0, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 279, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 880, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 429, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 8, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 5428, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 8605, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 58, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 1224, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 19229, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 17830, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 756, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 0, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 2260, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 2873, square: [ [Object], [Object], [Object], [Object] ] },
    { mag: 1923, square: [ [Object], [Object], [Object], [Object] ] }
  ]
  </code></pre>
  <p>Instead I am getting a result with all magnitudes set to 0</p>