开发者

Proper architecture for Node.js modules and database connectivity?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜