Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:12:02+00:00 2026-06-15T22:12:02+00:00

I am building a reddit API wrapper in node.js to become more familiar with

  • 0

I am building a reddit API wrapper in node.js to become more familiar with js and node. Here is my code so far:

./lib/reddit.js:

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 && response.statusCode == 200) {
        callback(body);
      }
    });
  };

  self.post = function (url, data, callback) {
    request.post(url, { form: data }, function (error, response, body) {
      if (!error && 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;

app.js:

var reddit = require("./lib.reddit").reddit;
reddit.login("username", "password");

I get this error:

[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 && response.statusCode == 200) {
        callback(body);
      }
    });
  };

  self.post = function (url, data, callback) {
    request.post(url, { form: data }, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        callback(body);
      }
    });
  };

} has no method 'login'
at Object.<anonymous> (/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)

I originally had the login function defined like

reddit.prototype.login = function () .....

but this doesn’t work either. Another SO question recommended formatting it like I have it now, but it still doesn’t recognize it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:12:04+00:00Added an answer on June 15, 2026 at 10:12 pm
    var reddit = require("./lib.reddit").reddit;
    
    var a = new reddit();
    
    a.login("username", "password");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a string for post request in the following way, var itemsToAdd = sl.SelProds.ToList();
I'm building a Hacker-News or Reddit style social news site with MongoDB. Let's suppose
I'm building a site that has somewhat reddit-like functionality. I want user-submitted content to
Building a simple app here; the methods in question: static coin class public static
Building my code (below) returns error 'imread' is not a member of 'cv' .
Building a sample ASP.NET MVC app. Using the Membership API for authentication. For whatever
building libraries with waf is nice and I like the lib<targetname> naming scheme. But
Building an app using android.support.v4.app , targeting API level 8. Everything's working as planned
For educational purposes, I am building a clone social bookmarking service (similar to reddit).
building a simple calculator here to get my feet wet with iOS dev. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.