title: How does require() in node.js work?
body: <p>I tried this:</p>
  
  <pre><code>// mod.js
  var a = 1;
  this.b = 2;
  exports.c = 3;
  
  // test.js
  var mod = require('./mod.js');
  console.log(mod.a);    // undefined
  console.log(mod.b);    // 2
  console.log(mod.c);    // 3, so this === exports?
  </code></pre>
  
  <p>So I image that require() may be implement like this:</p>
  
  <pre><code>var require = function (file) {
      var exports = {};
      var run = function (file) {
          // include "file" here and run
      };
      run.apply(exports, [file]);
      return exports;
  }
  </code></pre>
  
  <p>Is that right? Please help me to understand require(), or where can I find the source code. Thanks!</p>