title: In Node.js, referring to one function from another within the same file results in a 'ReferenceError: -function- is not defined' error
body: <p>In a node.js application, attempts to reference one function from within another function in the same file (<em>index.js</em>) results in the error, <strong>ReferenceError: familyLookup is not defined</strong>.</p>
  
  <p>The intention is to have the second function, <em>schedule</em>, call <em>familyLookup</em>. How can I fix this?</p>
  
  <p><em>index.js</em></p>
  
  <pre><code>exports.familyLookup = function(oid, callback){
      var collection = db.get('usercollection');
      collection.findOne( 
          { _id : oid }, 
          { address: 1, phone: 1 }, 
          function(e, doc){
              console.log(doc);
          }
      )
  }
  
  
  exports.schedule = function(db, callback){
      return function(req, res) {
          var lookup = familyLookup();
          var schedule_collection = db.get('schedule');
          var today = new Date();
          var y = [];
  
          schedule_collection.find({ date : {$gte: today}},{ sort: 'date' },function(err, docs){
              for ( var x in docs ) {
                  var record = docs[x];
                  var oid = record.usercollection_id;
                  result = lookup(db,oid)
                  record.push(lookup(oid));
                  y.push(record);
              }
  
              res.render('schedule', {
                  'schedule' : y,
              });
          });
      };
  };   
  </code></pre>