4

I have a task where I would need to make multiple queries (> 10) based on the outcome of previous tasks. I created a connection pool using node-mysql module.

var pool  = mysql.createPool({
        connectionLimit: 10,
        host     : config.mysql.host,
        user     : config.mysql.user,
        password : config.mysql.password,
        database : config.mysql.database
    });

pool.getConnection(function(err, connection) {
        //execute task1 -> task2 -> task3,4,5 and so on
    })

Now this pool is created in the base module. The base module further uses 5-6 other modules to handle sub tasks. Each of these modules need to make queries to the DB. I was wondering if I should pass this 'pool' variable to each module and get a connection from the pool for each query. Or should I get a connection from the pool in the base module and pass the same connection around. Or if there is a better way to share a common mysql connection pool across modules in nodejs?

Rahul Nanwani
  • 1,267
  • 1
  • 10
  • 21
  • Possible duplicate of [How to properly pass mysql connection to routes with express.js](http://stackoverflow.com/questions/16800418/how-to-properly-pass-mysql-connection-to-routes-with-express-js) – dev Mar 28 '16 at 23:27

0 Answers0