Categories
JavaScript Answers

How to fix cannot enqueue Handshake after invoking quit with Node.js MySQL?

Spread the love

To fix cannot enqueue Handshake after invoking quit with Node.js MySQL, we create a connection pool.

For instance, we write

const mysql = require("mysql");
const pool = mysql.createPool({
  //...
});

pool.getConnection((err, connection) => {
  connection.query("...", (err, rows) => {
    connection.release();
  });
});

to call createPool tro create a connection pool.

Then we call getConnection to get the database connection.

And we call query to make the query with the connection in the callback.

Once we’re done, we call release to release the connection.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *