Node.js MySQL integration Query a connection object without parameters


You send the query as a string and in response callback with the answer is received. The callback gives you error, array of rows and fields. Each row contains all the column of the returned table. Here is a snippet for the following explanation.

connection.query('SELECT name,email from users', function(err, rows, fields) {
  if (err) throw err;

  console.log('There are:', rows.length,' users');
  console.log('First user name is:',rows[0].name)