title: nodejs - Call a function inside a parent module from a child module
body: <p>Let's say I have a file called <code>parent.js</code> with the following source code:</p>
  
  <pre><code>var child = require('./child')
  
  var parent = {
      f: function() {
          console.log('This is f() in parent.');
      }
  };
  
  module.exports = parent;
  
  child.target();
  </code></pre>
  
  <p>and a file called <code>child.js</code> with the following source code:</p>
  
  <pre><code>var child = {
      target: function() {
          // The problem is here..
      }
  }
  
  module.exports = child;
  </code></pre>
  
  <p>and I execute the file using the following command:</p>
  
  <pre><code>node parent.js
  </code></pre>
  
  <p>The thing is, I want to execute <code>f()</code> inside <code>child.js</code> directly without using any <code>require(...)</code> statement. Previously, I'm trying to execute this statement inside <code>target()</code> in <code>child.js</code>:</p>
  
  <pre><code>module.parent.f()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>module.parent.exports.f()
  </code></pre>
  
  <p>but it doesn't work. The strange thing is, when I execute <code>console.log(module.parent.exports)</code> inside <code>child.js</code>, the following output appear:</p>
  
  <pre><code>{ f: [Function] }
  </code></pre>
  
  <p>So why can't I call <code>f()</code> directly?</p>