npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-reddit-js

v0.0.11

Published

A Node.js Reddit module that attempts to fully cover the Reddit API.

Downloads

6

Readme

node-reddit-js

A Node.js Reddit module that attempts to fully cover the Reddit API.

This is not done yet, currently YOU have to make the requests to the endpoints yourself, but soon it'll all be done in the background for you.

Examples

Importing the package:

// import the package
const Reddit = require("node-reddit-js")
// import only the client class
const { Client } = require("node-reddit-js")

Using the package - with credentials

const client = new Reddit.Client({
  id: "APP_ID",
  secret: "APP_SECRET",
  username: "REDDIT_USERNAME",
  password: "REDDIT_PASSWORD",
})

client.api.v1.me.karma.get() // GET https://oauth.reddit.com/api/v1/me/karma
/*
{
  kind: 'KarmaList',
  data: [
    { sr: 'dankmemes', comment_karma: 65, link_karma: 6985 },
    { sr: 'memes', comment_karma: 231, link_karma: 6074 },
    // ...
  ]
}
*/

Some endpoints don't require authorisation:

// don't authorise with the token
client.reddit.new.get({ auth: false }) // GET https://reddit.com/new
/*
{
  kind: "Listing",
  data: {
    // ...
  }
}
*/

Using the package - without credentials

const client = new Reddit.Client()
client.reddit.r.dankmemes.comments.jiiz5o.get({ auth: false }) // GET https://www.reddit.com/r/dankmemes/comments/jiiz5o
/*
[
  // post
  {
    kind: "Listing",
    data: {
      // ...
    }
  },

  // comments
  { 
    kind: "Listing",
    data: {
      // ...
    }
  }
]
*/

API

// The url changes from oauth.reddit.com to www.reddit.com if you're not authorising
// i'll just use reddit.com here to keep things simple

client.reddit // https://reddit.com
client.api    // https://reddit.com/api (shortcut, client.reddit.api)
client.v1     // https://reddit.com/api/v1 (shortcut again, client.reddit.api.v1 or client.api.v1)

client.reddit.top         // https://reddit.com/top
client.reddit.r.subreddit // https://reddit.com/r/subreddit

client.reddit("r/subreddit") // https://reddit.com/r/subreddit
client.reddit["r/subreddit"] // https://reddit.com/r/subreddit

client.reddit.a.b("c", "d").e["f"]  // https://reddit.com/a/b/c/d/e/f

// Making requests
client.reddit.new.get({             // GET https://reddit.com/new?limit=2
  data: {
    limit: 2
  }
})
client.api.whatever.you.want.post({ // POST https://reddit.com/whatever/you/want with data {"some":"thing"}
  data: {
    some: "thing"
  }
}) 
client.v1.me.prefs.patch({          // PATCH https://reddit.com/api/v1/me/prefs with data {...}
  data: {
    // ...
  }
})
// any data you need to send or query onto the url goes into the data field