Reputation: 6951
im new to nodejs, and I am looking for ways to have a pub/sub messaging in my node application that I can use for communication between module/packages.
Was looking into using EventEmitter maybe using the eventEmitter instance on the process so it can act as a global event bus. But I just have a bad feeling about doing that, I don't know node enough to come up with a solid reason to not doing that.
or is there an alternative approach?
this is only in memory not cross multiple instance
Upvotes: 1
Views: 1409
Reputation: 36329
You can rely on the module cache if you like. Some modules do that to maintain state if needed (e.g. mongoose).
So what I mean by that is if your message bus module maintains its state internally, and exports the pub/sub functions only, then any other module that requires it will get the same 'instance' and therefore be able to pub/sub against the same channel.
Upvotes: 1