开发者

Proper architecture for Node.js modules and database connectivity?

开发者 https://www.devze.com 2023-03-17 18:14 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消