Proper architecture for Node.js modules and database connections?

I am writing a Node application that accepts TCP connections. I have several separate Node modules (using export functions). Each of them requires a database connection.

What is the best way to architect / handle database connections? Should each module create a separate connection, or should my main JS file go through the handler for connecting the database to the modules when I require them?

+4
source share
1 answer

imo the best approach is to initialize the connection pool and use it in modules passing as a parameter. mysql-pool is pretty generic and easily adapts to any db client

upd: node-pool - db-agnostic shared pool

+6
source

All Articles