title: How to do a bulk insert with node-postgres
body: <p>I am importing an excel file into a postgres database with express and node-pg</p>
  
  <p>Currently I am looping through the excel rows and executing an insert for every row but I feel it's not the right way:</p>
  
  <pre><code>workbook.xlsx.readFile(excel_file).then(function () {
          // get the first worksheet          
          var worksheet = workbook.getWorksheet(1);
          // Loop through all rows
          worksheet.eachRow(function (row, rowNumber) {
              // Commit to DB only from line 2 and up. We want to exclude headers from excel file
              if (rowNumber &gt; 1) {
                  // Loop through all values and build array to pass to DB function
                  row.eachCell(function (cell, colNumber) {
                      arrSQLParams.push(cell.value)                   
                  })
  
                  // Add the user id from session to the array
                  arrSQLParams.push(user);
  
                  // Insert into DB
                  db.query(strSQL, arrSQLParams, function (err, result) {
                      if (err) {
                          console.log(err);
                              ret = false;
                          }
                  })
  
                  // Empty the array for new query
                  arrSQLParams = [];
              }
          })          
      });
  </code></pre>
  
  <p>Is there a better way to do this to improve performance?</p>