Skip to content

Commit 95560df

Browse files
committed
feat: initial release v0.1.0 — official FetchLayer Reddit SDK
0 parents  commit 95560df

15 files changed

Lines changed: 3286 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
.DS_Store
5+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 HootCodes LTD
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# Reddit Scraper & API Client for JavaScript / TypeScript
2+
3+
[![npm](https://img.shields.io/npm/v/@fetchlayer/reddit)](https://www.npmjs.com/package/@fetchlayer/reddit)
4+
[![license](https://img.shields.io/npm/l/@fetchlayer/reddit)](https://github.com/fetchlayer/reddit-scraper-js/blob/main/LICENSE)
5+
[![types](https://img.shields.io/npm/types/@fetchlayer/reddit)](https://www.npmjs.com/package/@fetchlayer/reddit)
6+
7+
The official JavaScript & TypeScript SDK for the [FetchLayer](https://fetchlayer.dev) Reddit API.
8+
9+
Search posts. Scrape comments. Pull subreddit data. Get user profiles. All as clean JSON from a single API — no scraping infrastructure, no proxies, no HTML parsing.
10+
11+
> **Open-source SDK, hosted API.** This package is MIT-licensed. The API requires a free [FetchLayer API key](https://fetchlayer.dev/signin) — no subscriptions, no contracts, no lock-in. Pay only for what you use.
12+
13+
---
14+
15+
## Install
16+
17+
```bash
18+
npm install @fetchlayer/reddit
19+
```
20+
21+
```bash
22+
pnpm add @fetchlayer/reddit
23+
```
24+
25+
```bash
26+
yarn add @fetchlayer/reddit
27+
```
28+
29+
## Get your API key
30+
31+
1. Go to [fetchlayer.dev](https://fetchlayer.dev/signin)
32+
2. Sign in with your email
33+
3. Copy your API key from the dashboard
34+
35+
That's it. No credit card. No trial expiration. You get free requests to start, then pay-as-you-go at $1.99 per 1,000 requests when you need more.
36+
37+
## Quick start
38+
39+
```ts
40+
import { FetchLayerReddit } from "@fetchlayer/reddit";
41+
42+
const reddit = new FetchLayerReddit({
43+
apiKey: process.env.FETCHLAYER_API_KEY!,
44+
});
45+
46+
// Search Reddit for posts about any topic
47+
const results = await reddit.searchPosts({
48+
query: "best CRM tools",
49+
sort: "top",
50+
time: "month",
51+
limit: 10,
52+
});
53+
54+
console.log(results);
55+
```
56+
57+
**That's 4 lines to get structured Reddit data.** No OAuth, no rate-limit wrestling, no broken scrapers.
58+
59+
---
60+
61+
## Why use this instead of scraping Reddit yourself
62+
63+
| Problem | FetchLayer |
64+
| --- | --- |
65+
| Reddit blocks your IP | We handle rotation and resilience |
66+
| HTML structure changes break your parser | You get stable JSON |
67+
| Reddit API has strict OAuth + rate limits | Simple Bearer token, no rate limits |
68+
| Maintaining scraping infra is a full-time job | `npm install` and done |
69+
| You need comments, users, AND search | 13 endpoints, one SDK |
70+
71+
---
72+
73+
## All methods
74+
75+
```ts
76+
const reddit = new FetchLayerReddit({ apiKey });
77+
```
78+
79+
| Method | What it does |
80+
| --- | --- |
81+
| `reddit.searchPosts(params)` | Search Reddit posts by keyword |
82+
| `reddit.getPost(params)` | Get a post with its full comment tree |
83+
| `reddit.getCommentPermalink(params)` | Get a specific comment thread |
84+
| `reddit.getCommunityPosts(params)` | List posts from any subreddit |
85+
| `reddit.getCommunityDetails(params)` | Get subreddit metadata and stats |
86+
| `reddit.getUserProfile(params)` | Get a Reddit user's profile |
87+
| `reddit.getUserPosts(params)` | List all posts by a user |
88+
| `reddit.getUserComments(params)` | List all comments by a user |
89+
| `reddit.searchCommunities(params)` | Find subreddits by keyword |
90+
| `reddit.searchUsers(params)` | Find Reddit users by name |
91+
| `reddit.getPopularPosts(params)` | Get what's trending on Reddit |
92+
| `reddit.getLeaderboard(params)` | Get top communities by activity |
93+
| `reddit.resolveUrlType(params)` | Detect what a Reddit URL points to |
94+
95+
---
96+
97+
## Examples
98+
99+
### Search posts across Reddit
100+
101+
```ts
102+
const posts = await reddit.searchPosts({
103+
query: "side project ideas",
104+
subreddit: "startups", // optional — omit to search all of Reddit
105+
sort: "relevance",
106+
time: "week",
107+
limit: 25,
108+
});
109+
```
110+
111+
### Get a full post with comments
112+
113+
```ts
114+
const thread = await reddit.getPost({
115+
url: "https://www.reddit.com/r/webdev/comments/abc123/my_post/",
116+
commentLimit: 100,
117+
commentDepth: 4,
118+
});
119+
```
120+
121+
### Browse a subreddit
122+
123+
```ts
124+
const hot = await reddit.getCommunityPosts({
125+
subreddit: "javascript",
126+
sort: "hot",
127+
limit: 25,
128+
});
129+
```
130+
131+
### Look up a user
132+
133+
```ts
134+
const profile = await reddit.getUserProfile({ username: "spez" });
135+
const posts = await reddit.getUserPosts({ username: "spez", limit: 10 });
136+
const comments = await reddit.getUserComments({ username: "spez", limit: 10 });
137+
```
138+
139+
### Discover trending content
140+
141+
```ts
142+
const popular = await reddit.getPopularPosts({ time: "day", limit: 10 });
143+
const topCommunities = await reddit.getLeaderboard({ limit: 10 });
144+
```
145+
146+
---
147+
148+
## Error handling
149+
150+
```ts
151+
import { FetchLayerReddit, FetchLayerError } from "@fetchlayer/reddit";
152+
153+
try {
154+
const posts = await reddit.searchPosts({ query: "test" });
155+
} catch (err) {
156+
if (err instanceof FetchLayerError) {
157+
console.error(err.status); // 401, 429, etc.
158+
console.error(err.message); // Human-readable error from the API
159+
}
160+
}
161+
```
162+
163+
---
164+
165+
## Configuration
166+
167+
```ts
168+
const reddit = new FetchLayerReddit({
169+
apiKey: "your-key", // Required
170+
baseUrl: "...", // Default: https://fetchlayer.dev/api/reddit
171+
timeoutMs: 30000, // Default: 30s
172+
fetch: customFetch, // Default: global fetch (Node 18+)
173+
});
174+
```
175+
176+
---
177+
178+
## What this package is
179+
180+
- **Zero dependencies** — uses native `fetch`, nothing else
181+
- **Dual build** — ESM + CommonJS, works everywhere
182+
- **Fully typed** — TypeScript declarations included
183+
- **Tiny** — under 6 KB bundled
184+
- **Open source** — MIT license, contributions welcome
185+
186+
## How it works
187+
188+
You call FetchLayer → FetchLayer returns structured Reddit data as JSON → you use it however you want.
189+
190+
No Reddit account needed. No OAuth setup. No scraping infrastructure on your end.
191+
192+
---
193+
194+
## Pricing
195+
196+
| | |
197+
| --- | --- |
198+
| **Free tier** | Included with every account — start building immediately |
199+
| **Pay-as-you-go** | $1.99 per 1,000 requests. Credits never expire. |
200+
| **Subscriptions** | Available for heavy use — predictable pricing at scale |
201+
| **Rate limits** | None |
202+
203+
No credit card required to start. No monthly commitment. No overages. [Get your API key →](https://fetchlayer.dev/signin)
204+
205+
---
206+
207+
## Use cases
208+
209+
- **Market research** — find what people say about your product or competitors on Reddit
210+
- **Lead generation** — discover posts where people ask for solutions you offer
211+
- **Content research** — find trending topics and discussions in your niche
212+
- **Sentiment analysis** — pull comments and run NLP on real user opinions
213+
- **Competitive intelligence** — monitor mentions of any brand or product
214+
- **AI agents** — give your LLM real-time Reddit context via FetchLayer's [MCP server](https://fetchlayer.dev/reddit-scraper)
215+
216+
---
217+
218+
## Links
219+
220+
| | |
221+
| --- | --- |
222+
| **Get API key** | [fetchlayer.dev/signin](https://fetchlayer.dev/signin) |
223+
| **Product page** | [fetchlayer.dev/reddit-scraper](https://fetchlayer.dev/reddit-scraper) |
224+
| **Homepage** | [fetchlayer.dev](https://fetchlayer.dev) |
225+
| **npm** | [@fetchlayer/reddit](https://www.npmjs.com/package/@fetchlayer/reddit) |
226+
| **Issues** | [GitHub Issues](https://github.com/fetchlayer/reddit-scraper-js/issues) |
227+
228+
---
229+
230+
## License
231+
232+
MIT — see [LICENSE](LICENSE).

examples/discover.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FetchLayerReddit } from '../src';
2+
3+
const client = new FetchLayerReddit({
4+
apiKey: process.env.FETCHLAYER_API_KEY ?? '',
5+
});
6+
7+
const [communities, users, popular] = await Promise.all([
8+
client.searchCommunities({ query: 'saas', limit: 5 }),
9+
client.searchUsers({ query: 'alex', limit: 5 }),
10+
client.getPopularPosts({ limit: 5, time: 'day' }),
11+
]);
12+
13+
console.log({ communities, users, popular });

examples/get-post.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FetchLayerReddit } from '../src';
2+
3+
const client = new FetchLayerReddit({
4+
apiKey: process.env.FETCHLAYER_API_KEY ?? '',
5+
});
6+
7+
const result = await client.getPost({
8+
url: 'https://www.reddit.com/r/programming/comments/1abcxyz/example_post/',
9+
commentLimit: 100,
10+
commentDepth: 4,
11+
});
12+
13+
console.log(JSON.stringify(result, null, 2));

examples/search-posts.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FetchLayerReddit } from '../src';
2+
3+
const client = new FetchLayerReddit({
4+
apiKey: process.env.FETCHLAYER_API_KEY ?? '',
5+
});
6+
7+
const results = await client.searchPosts({
8+
query: 'best crm tools',
9+
subreddit: 'sales',
10+
sort: 'top',
11+
time: 'month',
12+
limit: 10,
13+
});
14+
15+
console.log(JSON.stringify(results, null, 2));

0 commit comments

Comments
 (0)