title: Node.js TypeError: undefined is not a function
body: <p>I'm trying to call this function on my model User(I'm using mongoose). like this:</p>
  
  <pre><code>UserSchema.statics.exists = function exists(req,email, callback) {
      this.findOne({
          email : email
      }, function(err, user,callback) {
          if(err) {
              console.error(err);
              return callback(err);
          }
          if(!user) {
              // console.log("Not user");
              return callback(null, false);// produce error
          }
          if(!user.valid) {
              console.log("User invalid");
              var hostname = req.headers.host;
              // hostname = 'localhost:8080'
              //var pathname = url.parse(req.url).pathname; // pathname = '/MyApp'
  
              var base_url = 'http://' + hostname + '/activation?key=' + user.account_no;
              user.verifyEmail(base_url, user, function(err, result) {
                  if(err) {
                      console.error(err);
                  return  callback(err);
                  } else {
                      //if(email sent)
                      if(result) {
                      return  callback("Please check your email to activate your account");
                      } else {
                      return  callback("Activation error please contact WOWITO support");
                      }
                  }
              });
          }
          return callback(null, user);
      });
  }
  </code></pre>
  
  <p>but then I got the following error:</p>
  
  <p>node.js:201
          throw e; // process.nextTick error, or 'error' event on first tick
                ^
  TypeError: undefined is not a function</p>
  
  <p>What did I do wrong? </p>
  
  <p>Thanks,</p>