I'm writing a Node app that accepts TCP connections. I have a few separate Node modules (utilizing the exports functionality). Each needs a database connection to handle some of their functionality.
What's the best way to architect/handle database connections? Should each module cr开发者_JS百科eate a separate connection or should my main JS file pass in a database connection handler to the modules when I require them?
imo best approach is to initialize connections pool and use it in modules passing as parameter. mysql-pool is quite generic and easily adaptable to any db client
upd: node-pool is a generic db-agnostic pool
精彩评论