title: eventemitter.on is getting registered and fired mutiple times in when using with sockets.io
body: <p>I want to call an io.emit('eventname') event of socket.io, when a custom event is triggered in another file in node.js. this happens in response to an HTTP request for a frontend app</p>
  <p>moreover, I have created a common event emitter as simple importing and exporting the events was not firing, as expected, between files in node.js</p>
  <p><strong>commonEventEmitter.js</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var events = require('events')
  var em = new events.EventEmitter()
  
  module.exports.commonEmitter = em;</code></pre>
  </div>
  </div>
  </p>
  <p>This file receiles the HTTP request and triggers an event i.e 'newSOS, registered in <strong>socket.js</strong> file</p>
  <p><strong>sosRequest.js</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const common = require('../utils/commonEventEmitter')
  const commonEvent = common.commonEmitter
      
  
  exports.createSOS = asyncHandler( async (req,res,next) =&gt; {
      const { type , location } = req.body
      Request = await SOS.findOne({type : type , createdBy: req.commuter[0].id , 
                status:'Pending'})
  
       commonEvent.emit('newSOS')
        
       const request = await SOS.create({
      
       type,
       location,
       createdBy,
      })  
  
      res.status(200).json({
        success:true,
        request
      })</code></pre>
  </div>
  </div>
  </p>
  <p>In this file, 'newSOS' event is registered and is called many times as on an HTTP request is received.</p>
  <p><strong>socket.js</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const io = require('socket.io')()
  // const eventHandlers = require('./eventHandlers');
  const common = require('../utils/commonEventEmitter')
  const commonEvent = common.commonEmitter
  
  io.on('connection' , (socket)=&gt;{
  
  commonEvent.on('newSOS' , ()=&gt; {
          console.log('running only once'.bgGreen)
              io.emit('sos_admin' , "just do it")
      })
  }
  
  
  module.exports = io</code></pre>
  </div>
  </div>
  </p>
  <p>It's getting executed multiple times in 1 page. The pattern as follows:</p>
  <p>If page is loaded first time it will be executed once.
  If page is loaded second time it will be executed twice.
  If page is loaded n times it will be executed n times.</p>
  <p>and please also tell if my io.on('connection') is getting called multiple times?</p>