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 🙏

© 2025 – Pkg Stats / Ryan Hefner

reddit-node-sdk

v1.0.2

Published

Minimal Reddit API SDK for Node.js

Readme

Reddit Node SDK

A minimal Reddit API SDK for Node.js using native fetch API.

Features

  • 🚀 Minimal and lightweight
  • 📦 Zero dependencies (uses native Node.js fetch)
  • 🔐 OAuth2 access token authentication
  • 📘 Full TypeScript support
  • 🗂️ Modular structure with separated concerns

Installation

npm install reddit-node-sdk

Quick Start

import { RedditClient } from 'reddit-node-sdk';

const client = new RedditClient('your-app-name/1.0');

const me = await client.getMe(accessToken);
console.log(`Hello, ${me.name}!`);

Project Structure

src/
├── types/           # TypeScript type definitions
│   ├── common.ts    # Common types (RequestContext, options)
│   └── account.ts   # Account endpoint types
├── endpoints/       # Endpoint implementations
│   └── account.ts   # Account-related endpoints
└── RedditClient.ts  # Main client class

API Reference

RedditClient

Constructor

new RedditClient(userAgent: string, options?: RedditClientOptions)
  • userAgent (required): A unique identifier for your application
  • options (optional):
    • baseUrl: Custom API base URL (default: https://oauth.reddit.com)

Account Endpoints

All methods require a valid OAuth2 accessToken as the first parameter.

getMe(accessToken, options?)

Get information about the authenticated user.

const me = await client.getMe(accessToken);
console.log(me.name, me.total_karma);

Returns: RedditMeResponse with fields:

  • name, id, created_utc
  • link_karma, comment_karma, total_karma
  • verified, is_gold, has_verified_email
  • subreddit (user profile subreddit)
  • And many more...

getKarma(accessToken, options?)

Get breakdown of karma by subreddit.

const karma = await client.getKarma(accessToken);
karma.data.forEach(entry => {
  console.log(`r/${entry.sr}: ${entry.link_karma} link, ${entry.comment_karma} comment`);
});

Returns: KarmaListResponse

Note: This endpoint may not be available for all accounts (returns 404).

getPrefs(accessToken, options?)

Get user preference settings.

const prefs = await client.getPrefs(accessToken);
console.log(`Language: ${prefs.lang}, Night mode: ${prefs.nightmode}`);

Options:

  • fields: Comma-separated list of preference fields to return

Returns: UserPreferences with fields like:

  • lang, country_code
  • nightmode, over_18
  • default_comment_sort, num_comments
  • email_* preferences
  • And 60+ other preference fields

updatePrefs(accessToken, prefs)

Update user preferences.

await client.updatePrefs(accessToken, {
  nightmode: true,
  lang: 'en'
});

Parameters:

  • prefs: Partial object with preferences to update

Returns: Updated UserPreferences

getTrophies(accessToken, options?)

Get list of trophies for the current user.

const trophies = await client.getTrophies(accessToken);
trophies.data.trophies.forEach(trophy => {
  console.log(trophy.data.name);
});

Returns: TrophiesResponse with structure:

{
  kind: "TrophyList",
  data: {
    trophies: Trophy[]
  }
}

Research Notes

This SDK was built by testing actual Reddit API responses. Key findings documented in code:

Account Endpoints (/api/v1/me/*)

  • GET /api/v1/me: Returns comprehensive user account data (30+ fields)
  • GET /api/v1/me/karma: Returns karma breakdown by subreddit (may return 404 for some accounts)
  • GET /api/v1/me/prefs: Returns flat JSON object with 60+ preference settings
  • PATCH /api/v1/me/prefs: Accepts partial JSON to update specific preferences
  • GET /api/v1/me/trophies: Returns {kind: "TrophyList", data: {trophies: []}}

All endpoints require:

  • Authorization: Bearer {accessToken} header
  • User-Agent: {your-user-agent} header

Example

See examples/basic-usage.ts for a complete working example.

export REDDIT_ACCESS_TOKEN="your-token-here"
npm run example

Expected output:

=== Testing Account Endpoints ===

1. GET /api/v1/me
   Username: your_username
   ID: xxxxx
   Karma: 123 (Link: 100, Comment: 23)
   Verified: true
   Gold: false

2. GET /api/v1/me/prefs
   Language: en
   Night mode: false
   Over 18: false
   ...

✓ All tests completed!

Development

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run example
npm run example

License

MIT