Categories
JavaScript Answers

How to add MySQL connection pooling with Node.js?

Spread the love

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.

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 *