title: nodejs not recognizing object's function
body: <p>I am building a reddit API wrapper in node.js to become more familiar with js and node.  Here is my code so far:</p>
  
  <p>./lib/reddit.js:</p>
  
  <pre><code>var request = require("request");
  
  var reddit = function () {
  
    var self = this,
    userAgent = "node.js api wrapper",
    debug = false,
    uh = "",
    cookie = "";
  
    self.getJSON = function (url, callback) {
      request(url, function (error, response, body) {
        if (!error &amp;&amp; response.statusCode == 200) {
          callback(body);
        }
      });
    };
  
    self.post = function (url, data, callback) {
      request.post(url, { form: data }, function (error, response, body) {
        if (!error &amp;&amp; response.statusCode == 200) {
          callback(body);
        }
      });
    };
  
  };
  
  reddit.prototype = {
  
    login: function (username, password) {
      var data = {
        "user": username,
        "password": password,
        "rem": true
      };
  
      this.post("http://www.reddit.com/api/login", data, function (body) {
        var response = JSON.parse(body);
        this.uh = response.json.data.modhash;
        this.cookie = response.json.data.cookie;
        console.log(response);
        console.log(this.uh);
        console.log(this.cookie);
      });
    }
  
  }
  
  exports.reddit = reddit;
  </code></pre>
  
  <p>app.js:</p>
  
  <pre><code>var reddit = require("./lib.reddit").reddit;
  reddit.login("username", "password");
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>[jet@cowboybebop reddit]$ node app.js 
  
  /home/jet/projects/reddit/app.js:5
  reddit.login("username", "password");
     ^
  TypeError: Object function () {
  
    var self = this,
        userAgent = "node.js api wrapper",
        debug = false,
        uh = "",
        cookie = "";
  
    self.getJSON = function (url, callback) {
      request(url, function (error, response, body) {
        if (!error &amp;&amp; response.statusCode == 200) {
          callback(body);
        }
      });
    };
  
    self.post = function (url, data, callback) {
      request.post(url, { form: data }, function (error, response, body) {
        if (!error &amp;&amp; response.statusCode == 200) {
          callback(body);
        }
      });
    };
  
  } has no method 'login'
  at Object.&lt;anonymous&gt; (/home/jet/projects/reddit/app.js:5:8)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.runMain (module.js:492:10)
  at process.startup.processNextTick.process._tickCallback (node.js:244:9)
  </code></pre>
  
  <p>I originally had the login function defined like</p>
  
  <pre><code>reddit.prototype.login = function () .....
  </code></pre>
  
  <p>but this doesn't work either.  Another SO question recommended formatting it like I have it now, but it still doesn't recognize it.  </p>