title: NodeJS - How to reference function in one require() file from another require() file?
body: <p>This is my second weekend playing with Node, so this is a bit newbie.</p>
  
  <p>I have a js file full of common utilities that provide stuff that JavaScript doesn't.  Severely clipped, it looks like this:</p>
  
  <pre><code>module.exports = {
      Round: function(num, dec) {
          return Math.round(num * Math.pow(10,dec)) / Math.pow(10,dec);
      }
  };
  </code></pre>
  
  <p>Many other custom code modules - also included via require() statements - need to call the utility functions.  They make calls like this:</p>
  
  <pre><code>module.exports = {
      Init: function(pie) {
          // does lots of other stuff, but now needs to round a number
          // using the custom rounding fn provided in the common util code
          console.log(util.Round(pie, 2)); // ReferenceError: util is not defined
      }
  };
  </code></pre>
  
  <p>The node.js file that is actually run is very simple (well, for this example).  It just require()'s in the code and kicks off the custom code's Init() fn, like this:</p>
  
  <pre><code>var util = require("./utilities.js");
  var customCode = require("./programCode.js");
  
  customCode.Init(Math.PI);
  </code></pre>
  
  <p>Well, this doesn't work, I get a "ReferenceError: util is not defined" coming from the customCode.  I know everything in each required file is "private" and this is why the error is occuring, but I also know that the variable holding the utility code object has GOT to be stored somewhere, perhaps hanging off of <code>global</code>?</p>
  
  <p>I searched through <code>global</code> but didn't see any reference to <code>utils</code> in there.  I was thinking of using something like <code>global.utils.Round</code> in the custom code.</p>
  
  <p>So the question is, given that the utility code could be referred to as anything really (var u, util, or utility), how in heck can I organize this so that other code modules can see these utilities?</p>