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.