'db.getConnection is not a not function Nodejs mysql

While I am trying to connect to the database it is giving me error

Database is MySQL,

express.js

//creating database connection
async function createDatabsePool( mysql = require('mysql2')){

return new Promise((resolve,reject)=>{
    const a =   mysql.createPool({

        host:process.env.HOST,
            user:process.env.USER,
            password:process.env.DATABASE_PASSWORD,
            database:process.env.DATABASE,
            port:process.env.DATABASE_PORT
          })

          
            return resolve(a);
    
})
        
         
    }
//const db =createDatabsePool(mysql)

async function connectDb(db = createDatabsePool(mysql)){
    return new Promise((resolve,reject)=>{
    db.getConnection(err=>{
    
        if(err){console.log(err,'err.......,');
            return reject(err);}
            return resolve(console.log('database connected...'))
    })    
    
    })
}

module.exports ={
    createDatabsePool,
    connectDb} 

index.js:-

const express1 = require('./express');


//---- database details ---------------
const db = express1.createDatabsePool(mysql)


//---- database connection ---------------
express1.connectDb(db);

error

backend\express.js:291
    db.getConnection(err=>{
       ^

TypeError: db.getConnection is not a function

I am calling the two functions createDatabsePool and connectDb in index.js

Can someone explain the error and suggest me some solutions. Also, recommend to me some good coding conventions which I am missing in my code and can implement.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source