title: understanding module.exports with callback
body: <p>I have a situation where I am creating a node module that returns only when an asynchronous operation is completed.  One way to do this (shown below), is to assign module.exports a function with a callback parameter.  Inside the function, you would then return the callback.  </p>
  
  <p>Here's an example of what I describe, with done being callback:</p>
  
  <pre><code>// module called test.js
  module.exports = function(done) {
    // do something asynchronous here
    process.nextTick(function() {
      done();  //  call done when the asynchronous thing is complete...
    }
  }
  </code></pre>
  
  <p>Where I am getting hung up, is in how the callback done is indeed being executed, considering I don't define it anywhere...</p>
  
  <p>For example, in vanilla javascript, I can pass done as parameter and then call it within the function, as long as I create the callback function in the invocation. </p>
  
  <pre><code>function testAsyncCb(msg, done) {
    console.log(msg);
    setTimeout( function() {
      done();
    }, 1000);
    console.log("last line in code");
  }
  
  testAsyncCb("testing", function(){ console.log("done"); });  // invocation with callback function
  </code></pre>
  
  <p>Back in the first node example, somewhere the call to module.exports by require() is creating a function for the done() to resolve to right?  If not, how is the callback resolving?</p>
  
  <p>Having a hard time finding information for how this works.  Any help/direction is appreciated.</p>