title: Node.js - sharing sockets among modules with require
body: <p>I'm using socket.io. In <code>app.js</code> I set up it and whenever a connection is established, I add the new socket to <code>sockets</code> array. I want to share <code>sockets</code> among modules such as <strong>routes</strong> by <code>require()</code>. However, <code>app.js</code> also requires the <strong>routes</strong>, so it forms a require loop. Here's the code.</p>
  
  <pre><code>// app.js
  var route = require('routes/route')
      , sockets = [];
  
  exports.sockets = sockets;
  
  // route.js
  var sockets = require('../app').sockets;  // undefined
  </code></pre>
  
  <p>How can I resolve the loop? Or are there other approaches?</p>