Skip to content

Simple wrapper to get Reddit posts from a subreddit using the .json feature

License

Notifications You must be signed in to change notification settings

Compositr/redditposts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redditposts

A simple wrapper to fetch reddit posts from a subreddit using the .json feature.

Installation

Deno

Simply import from our https://deno.land/x/ URL.

import { fetchPosts } from "https://deno.land/x/redditposts/src/mod.ts";

NodeJS

We do not officially support NodeJS. However it's really simple to port over to Node - simply download the code from our Github Repo and import the src/mod.ts file. Remember to polyfill the fetch function with something similar (e.g. node-fetch is a developer favourite)

The above assumes you are using TypeScript. If you are using JavaScript, you can do the same but strip away the types.

Examples

All examples assume you are using ESM and Deno

// Get all non-nsfw posts from the r/facepalm subreddit
import { fetchPosts } from "https://deno.land/x/redditposts/src/mod.ts";
const facepalms = await fetchPosts("facepalm", { filterNSFW: true });
console.log(facepalms);
// Get the top 100 memes in r/memes
import { fetchPosts } from "https://deno.land/x/redditposts/src/mod.ts";
const lotsOfMemes = await fetchPosts("memes", { amount: 100, category: "top" });
console.log(lotsOfMemes); // A huge array

License

MIT License. See LICENSE