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

@nickacide/redditjs

v0.0.1

Published

A JavaScript library for Reddit's API.

Downloads

4

Readme

RedditJS

npm downloads coverage-image Discord

RedditJS is a JavaScript library for interacting with Reddit's official API. Not only is it lightweight, it's also easy to use.

Install

Install via npm:

npm install --save js-reddit

RedditJS requires events and request-promise as dependencies.

Features

  • 100% Promise-based
  • Full coverage of Reddit's API
  • Extremely lightweight
  • Feels intuitive to use

Setup

To get started, you need to create an app. To understand how Reddit apps work, I suggest reading about it here.

Instructions:

  1. Create your app on Reddit (Either Web App or Script).
  2. Follow the next steps here.
  3. Acquire your refresh token, client id and client secret.

Usage

Now that you have everything you need, you can start writing some code. Here is an example for posting a link on Reddit.

const Reddit = require('js-reddit');
const client = new Reddit.Client({
	refresh_token: "refresh token",
	secret: "client secret",
	id: "client id"
});

client.on('authorized', () => {
	console.log(`Logged in! My token is ${client.token}`)
})

client.authenticate();

client.post('/api/submit', {
	sr: 'memes',
	resubmit: true,
	kind: 'link',
	title: 'Title for my Link',
	url: 'https://www.example.com'
}).then(results => {
	console.log(results)
});

Expected Output

{
  json: {
    errors: [],
    data: {
      url: 'link to message on reddit',
      drafts_count: 0,
      id: 'unique-ID',
      name: 't3_unique-ID'
    }
  }
}

Documentation

At the time of this writing, no Documentation exists yet, as this package lacks features. For now, the functionality of this package will be shown here. *Code is case-sensitive.

Client extends EventEmitter

Properties

  • Client.id The id of the app you created
  • Client.secret The secret of your app
  • Client.refresh_token The token used to generate access tokens
  • Client.token The access token (Regenerated every 3950 seconds)
  • Client.user_agent (Optional) Your User Agent. Always try provide one.

Methods

  • Client.authenticate() Authorize your app and generate an access token
  • Client.get(path, options) where path: The api path you want to invoke, options: The options required for the request
  • Client.put(path, options) where path: The api path you want to invoke, options: The options required for the request
  • Client.post(path, options) where path: The api path you want to invoke, options: The options required for the request
  • Client.patch(path, options) where path: The api path you want to invoke, options: The options required for the request
  • Client.delete(path, options) where path: The api path you want to invoke, options: The options required for the request

Events

  • authorized Emitted when the Client successfully authenticated.

FAQ

Questions can be asked by creating an Issue or asking in my Discord server. If you have a suggestion, please tell me! I am not online everyday, so do not expect the fastest responses. If you would like to become a contributor for this repository or a mod in my Discord server, simply ask!