title: Understanding Node.js modules: multiple requires return the same object?
body: <p>I have a question related to <a href="http://nodejs.org/docs/latest/api/modules.html#caching">the node.js documentation on module caching</a>:</p>
  
  <blockquote>
    <p>Modules are cached after the first time they are loaded. This means
    (among other things) that every call to require('foo') will get
    <strong>exactly the same object</strong> returned, if it would resolve to the same
    file.</p>
    
    <p>Multiple calls to require('foo') <strong>may not cause</strong> the module code to be
    executed multiple times. This is an important feature. With it,
    "partially done" objects can be returned, thus allowing transitive
    dependencies to be loaded even when they would cause cycles.</p>
  </blockquote>
  
  <p>What is meant with <code>may</code>?</p>
  
  <p>I want to know if require will <strong>always</strong> return the same object. So in case I require a module <strong>A</strong> in <code>app.js</code> and change the exports object within <code>app.js</code> (the one that require returns) and after that require a module <strong>B</strong> in <code>app.js</code> that itself requires module <strong>A</strong>, will I <strong>always</strong> get the modified version of that object, or a new one?</p>
  
  <pre><code>// app.js
  
  var a = require('./a');
  a.b = 2;
  console.log(a.b); //2
  
  var b = require('./b');
  console.log(b.b); //2
  
  // a.js
  
  exports.a = 1;
  
  // b.js
  
  module.exports = require('./a');
  </code></pre>