title: Socket.io connection keep increasing each time a new connect has been made
body: <p>I'm using Express4 with a router that points to path <code>/</code>, and that is handled by a JS file named <code>chat.js</code>.</p>
  
  <p>And my IO object is already bind to <code>app.io</code>, so inside my <code>chat.js</code> I'll call my Socket.IO by using <code>req.app.io</code>, but the problem is, I use to be using <code>socket.emit</code> and the code just work fine, but now if I want to sync up with the client I have to using <code>req.app.io.emit</code>.</p>
  
  <p>And since because I'm using <code>req.app.io.emit</code>, I have the connection keep increasing problem.</p>
  
  <hr>
  
  <p>index.js</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const http = require('http');
  const server = http.createServer(app);
  const path = require('path');
  const randomstring = require('randomstring');
  const sha256 = require('sha256');
  const io = require('socket.io').listen(server);
  app.io = io;
  const port = process.env.PORT || 3000;
  
  module.exports.users = {};
  
  server.listen(port, () =&gt; {
      console.log(`Serer is running on port ${port}`);
  });
  
  app.set('view engine', 'ejs');
  app.set('views', path.join(`${__dirname}/../public`));
  app.use('/static', express.static(path.join(`${__dirname}/../public`)));
  
  
  app.use('/', require('./chat'));
  </code></pre>
  
  <p>chat.js</p>
  
  <pre><code>const express = require('express');
  const router =  express.Router();
  const users = require('./index').users;
  const randomstring = require('randomstring');
  router.get('/', (req, res) =&gt; {
      res.render('index');
      const uid = randomstring.generate(30);
      users[uid] = true;
      req.app.io.on('connection', socket =&gt; {
          console.log('hello');
  
          socket.on('disconnect', () =&gt; {
              console.log('bye');
          });
  
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Log(Image)</p>
  
  <p><img src="https://image.prntscr.com/image/gIzJHNfuRWKQOILEBr46dA.png" /></p>
  
  <pre><code>Serer is running on port 3000
  hello
  bye
  hello
  hello
  bye
  bye
  </code></pre>