DEV Community

Cover image for Built a Reddit Memes & Jokes API with Node.js πŸš€
Jayant Navrange
Jayant Navrange

Posted on

Built a Reddit Memes & Jokes API with Node.js πŸš€

I've made a JSON API for memes, jokes, and funny posts from Reddit a long time ago for my small android app project, used it for a long time and then made it public, known as reddit-memes-api β€” a Node.js package + Express server that gives you JSON data for images, gifs, and videos from subreddits.


⚑ Features

  • Works with any subreddit you whitelist (memes, jokes, etc.).
  • Supports Reddit’s built-in sort: hot, new, top, rising.
  • Time filtering with day, week, month, year, all.
  • βœ… Pagination using after and before tokens.
  • βœ… Response includes marked_as_nsfw flag for post-level filtering.
  • βœ… Built-in rate limiting and caching (configurable via . env).

πŸ“¦ Installation

npm install reddit-memes-api
# or
yarn add reddit-memes-api
Enter fullscreen mode Exit fullscreen mode

πŸš€ API Reference

Type 1: Get subreddit data

GET /:subreddit

Type 2: Get sorted posts

GET /:subreddit/:memesare?limit=50

Type 3: Get sorted + time-filtered posts

GET /:subreddit/:memesare/:freq?limit=100

πŸ‘‰ Full parameter docs in the GitHub repo


πŸ”§ Example Requests

https://your-api.com/memes
https://your-api.com/memes/hot
https://your-api.com/memes/top/all?limit=100

And the JSON response looks like:

{
  "error": false,
  "code": 200,
  "type": "Success",
  "data": [
    {
      "author": "reddit_user",
      "title": "This meme made my day πŸ˜‚",
      "marked_as_nsfw": false,
      "post_hint": "image",
      "url": "https://i.redd.it/someimage.png"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Œ Node.js Usage

const { f1, f2, f3 } = require("reddit-memes-api");

(async () => {
  const memes = await f1("memes");
  const hot = await f2("jokes", "hot", 10);
  const topWeek = await f3("memes", "top", "week", 20);

  console.log(memes.data);
})();
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Env Example

URL=https://reddit.com/r/
PORT=3000

## Rate Limiting
RATE_LIMIT_WINDOW=60000
RATE_LIMIT_MAX=60

## Caching
CACHE_TTL=30
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Changelog Highlights

  • Added NSFW flag in response.
  • Added pagination (after, before).
  • Added rate limiting + caching.
  • Valid subreddit list in src/subredditList.

As it’s open-source β€” feel free to fork, improve, or suggest new features!
πŸ‘‰ GitHub Repo

I make this type of small projects, if you like my work and this content. Consider giving some motivation by reacting, commenting etc. on my post or follow/star my project on GitHub. Thanks for reading.

Top comments (0)