Q:

Node exports MySQL Pool Cluster

I'm new to node and I'm trying to use a MySQL pool cluster in but I'm not exactly sure how to export it. 
At the moment I have the following in /libs/mysql.js:
poolCluster.add('db1', {
    host: config.databases.hostname,
    user: config.databases.db1.username,
    password: config.databases.db1.password,
    database: config.databases.db1.database,
    connectionLimit: config.databases.connectionLimit
});

poolCluster.add('db2', {
    host: config.databases.hostname,
    user: config.databases.db2.username,
    password: config.databases.db2.password,
    database: config.databases.db2.database,
    connectionLimit: config.databases.connectionLimit
});

module.exports = {
    getConnection: (callback) => {
        return poolCluster.getConnection(callback);
    }
};

I'm trying to use it in models/monitor.js as below:
let poolCluster = require('../libs/mysql');
let moment = require('moment');

exports.select = function (sql, values, callback) {
    poolCluster.getConnection('db1', (err, connection) => {
        if (err) {
            callback(err);
        } else {
            connection.query(sql, values, (err, result) => {
                connection.release();
                if (err) {
                    console.log(err);
                    callback(err);
                } else {
                    callback(null, result)
                }
            })
        }
    })
};

The issue now is I'm getting an error stating cb is not a function. 
Is this the correct way to export a mysql pool cluster in node? 

A:

You are exporting as getConnection: (callback) => {} but you are calling the same function with getConnection(string, callback). 
According to the doc:
You can call getConnection like:
// Target Group : ALL(anonymous, MASTER, SLAVE1-2), Selector : round-robin(default)
poolCluster.getConnection(function (err, connection) {});

// Target Group : MASTER, Selector : round-robin
poolCluster.getConnection('MASTER', function (err, connection) {});

So, basically you need to pass the arguments you are getting from YOUR getConnection function to mysql's getConnection function. So this should do the trick:
module.exports = {
    getConnection: (...args) => {
        return poolCluster.getConnection(...args);
    }
};

