title: How to make object references available in Node modules?
body: <p>I have an Express.js web app. In the main <code>app.js</code> file, I <code>require()</code> a bunch of third party dependencies. Recently I've started extracting parts of my <code>app.js</code> code into separate modules, e.g.</p>
  
  <pre><code>// in app.js
  var users = require('./modules/users');
  
  // and then e.g.
  // users.add(doc);
  </code></pre>
  
  <p>Inside my modules, I sometimes need to use objects that are available in my main <code>app.js</code> file and I'm wondering what's the best way to pass references to those object to my modules.</p>
  
  <p>My current approach:</p>
  
  <pre><code>// in app.js
  
  // pass needed object references in initialization step
  users.init([db, logger]);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>// in modules/users.js
  
  var db, logger;
  
  exports.init = function (deps) {
      db = deps[0];
      logger = deps[1];
  };
  </code></pre>
  
  <p>Does this approach make sense? Is there a better way to perform this?</p>