title: How to use npm's 'events' module in Reactjs for eventEmitters
body: <p>I want to use npm's 'events' module in my React application. I have a game developed in phaserjs which also has level editor. The 'events' will used to communicate with the game module. 
    Folder Structure from root</p>
  
  <ul>
  <li>Client
  
  <ul>
  <li>src
  
  <ul>
  <li>App.js</li>
  <li>index.js</li>
  <li>Components/game-view</li>
  <li>Components/level-creator-view</li>
  </ul></li>
  </ul></li>
  <li>Game</li>
  <li>Server</li>
  </ul>
  
  <p>Some one had done same thing but in angular --
  in it's app.js</p>
  
  <pre><code>const eventEmitter = require('events').EventEmitter();
  window.eventEmitter = eventEmitter;
  eventEmitter.on('loaded', () =&gt; { console.log('\n\ncreator loaded\n\n') })
  </code></pre>
  
  <p>and in other states of his angular app he would just take --</p>
  
  <pre><code>const eventEmitter = window.eventEmitter;
  eventEmitter.emit('start game');
  </code></pre>
  
  <p><a href="https://github.com/LanaCoyote/girder-gus-maker" rel="nofollow noreferrer">Here's the link to that project,</a> look in browser module,app.js and also browser/states/createlevel</p>
  
  <p>I want to do the same exact thing,my project is similar but game logic is different.</p>
  
  <p>The game module has all the neccesary events emitters and listeners setup</p>
  
  <p>I have tried setting up window.eventsEmitter() in my index.js and using that in other components. Problem starts here, how do I use it in a React class or a function,should it be in constructor or should I set it up in lifecycle methods,or should I put it completely different js file and include it? I tried most(except for last one) but failed.</p>
  
  <p>I also searched about how to do it, haven't got exactly what I'm looking for..Any suggestion will be really helpful. Thanks in advance.</p>