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
andbefore
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
π 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"
}
]
}
π 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);
})();
βοΈ Env Example
URL=https://reddit.com/r/
PORT=3000
## Rate Limiting
RATE_LIMIT_WINDOW=60000
RATE_LIMIT_MAX=60
## Caching
CACHE_TTL=30
π‘ 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)