javascriptnode.jseventemitterfayednode

What's the most scale-friendly way to allow one node process to communicate between its own modules?


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 seems more suitable for inter-process communication - I want to isolate these internal messages to within the process.

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

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!


Solution

  • Dependency injection and invoking other modules directly works.

    So either

    var m = require("othermodule")
    
    m.doStuff();
    

    Or use a DI library like nCore