title: How to create a reusable Socket.IO module
body: <p>I have troubles for creating a module which exposes functionalities for my Socket.IO library:</p>
  
  <pre><code>const sio = require('socket.io');
  module.exports = function(server) {
    const io = sio(server);
    return {
      register: function(namespace) {
        let nsp = io.of(namespace);
        nsp.on('connect', function(socket) {
          // ...
        }
      }
    }
  }
  </code></pre>
  
  <p>The problem is now how do I make use of this in other modules? In my <code>app.js</code></p>
  
  <p>I create the <code>server</code> with Express and can instantiate the module with <code>require('./mysocketio')(server)</code> but not in other modules because server is not available there. What's a nice way to resolve these circular dependencies?</p>