Question

I've built a system whereby multiple modules are loaded into an "app.js" file. Each module has a route and schema attached. There will be times when a module will need to request data from another schema. Because I want to keep my code DRY, I want to communicate to another module that I want to request a certain piece of data and receive its response.

I've looked at using the following:

  • dnode (RPC calls)

Dnode seems more suitable for inter-process communication - I want to isolate these internal messages to within the process.

  • Faye (Pubsub)

Seems more like something used for inter-process communication, also seems like overkill

  • EventEmitter

I was advised by someone on #Node.js to stay away from eventEmitter if there are potentially a large amount of modules (and therefore a large amount of subscriptions)

Any suggestions would be very much appreciated!

JH

Was it helpful?

Solution

Dependency injection and invoking other modules directly works.

So either

var m = require("othermodule")

m.doStuff();

Or use a DI library like nCore

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top