Search code examples
node.jschild-process

sharing db connection with child_process in nodejs


I'm new at node.js and i wonder if there is any way to share a db-connection(lets say db-mysql) with a child_process. Can *child_process.fork()* do that if i communicating with the parent process by send SQL-statements back and get than the results?

Or is this in anyway worse than open a new Connection in the Child?


Solution

  • IMHO there is no advantage in sharing a connection over multiple processes. On the one hand, of course, you have fewer open connections, but on the other hand you have the overhead of inter-process communication.

    Hence I'd definitely prefer the one-connection-per-process approach.

    It's way less work, and way less overhead.