To add MySQL connection pooling with Node.js, we use the createPool
method.
For instance, we write
const mysql = require("mysql");
const pool = mysql.createPool({
host: "localhost",
user: "root",
password: "root",
database: "guess",
});
pool.getConnection((err, connection) => {
callback(err, connection);
});
to call createPool
to create a connection pool.
Then we call pool.getConnection
to get a connection and make queries with it.