title: Async Node JS query connection
body: <p>I am trying to create a excel workbook using excelbuilder and populating the data with information from a mysql database. This is my get method:</p>
  
  <pre><code> app.get('/excel', function(req, res) {
  
  var locationSpread = ['location1.xlsx', 'location2.xlsx', 
  'location3.xlsx'];
  
  locationSpread.forEach(function(filename) {
   fs.unlink("./Spreadsheets/" + filename, (err) =&gt; {
     if (err) {
       console.log('Spreadsheet ' + filename + ' not found');
     } else {
       console.log('Spreadsheet ' + filename + ' successfully found');
     }
   });
  
   var query = connection.query('SELECT * from ' + filename.slice(0, -5), function(err, rows) {
  
     var workbook = excelbuilder.createWorkbook('./Spreadsheets/', filename);
     var sheet = workbook.createSheet(filename.slice(0, -5), 3, rows.length);
     sheet.set(1, 1, 'First Name');
     sheet.set(2, 1, 'Last Name');
     sheet.set(3, 1, 'Company');
  
     *** TROUBLE CODE START HERE ***
     for (var j = 2, z = 0; z &lt; rows.length; j++, z++) {
       sheet.set(1, j, rows[z].firstName);
       sheet.set(2, j, rows[z].lastName);
       sheet.set(3, j, rows[z].company);
     }
     *** TROUBLE CODE END HERE ***
  
     workbook.save(function(err) {
       console.log('workbook saved ' + (err ? 'failed' : 'ok'));
     });
   });
   });
   });
  </code></pre>
  
  <p>The first thing I do is delete the files if they exist in the folder Spreadsheets. Then I query the database based on the location. I create a new workbook and sheet then write to it. The for loop breaks the program and while the error is:</p>
  
  <pre><code>TypeError: Cannot read property '1' of undefined
  </code></pre>
  
  <p>I believe it to be something along the lines of async</p>