0

I'm not new to programming, but new to NodeJS. I have a rather complex project that is now several modules deep, of course all rooted in app.js, similar to the following map:

App.js
    requires('Module_a')
    requires('Module_b')
    requires('EventEmitter2');


Module_a.js
    requires('Module_a1');
    requires('Module_a2');

Module_b.js
    requires('Module_b1');
    requires('Module_b2');

I want events generated in Module_a2 to be visible up at app.js and all the way down to Module_b2, and b2 events visible in a2, and so on. How best do I make the same instance of EventEmitter globally visible to all the modules?

Many thanks for your help

1 Answers1

1

It is best not to globalize it, but rather to require your Events module wherever needed. See here for a simple solution: How do you share an EventEmitter in node.js?

Community
  • 1
  • 1
glortho
  • 13,120
  • 8
  • 49
  • 45