How do you use the Reddit API in Node.js?
To use the Reddit API in Node.js, call api.redditapis.com with the built-in fetch and your bearer token in the Authorization header. There is no library to install and no OAuth flow: you sign up, copy your token, and read the clean JSON with await res.json(). The response carries a posts array. A read costs $0.002, and you start with $0.50 in free credits.
The full Node.js example
Global fetch, one request, parsed JSON. No snoowrap, no OAuth client, no refresh loop.
const url =
"https://api.redditapis.com/api/reddit/posts?subreddit=programming&sort=new&limit=25";
const res = await fetch(url, {
headers: { Authorization: "Bearer YOUR_TOKEN" },
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
const posts = data.posts;
console.log(`Got ${posts.length} posts`);
console.log(posts[0]);Why you can skip snoowrap
snoowrap wraps the official Reddit OAuth API, so it carries the app registration, scopes, and token refresh that OAuth requires. Redditapis replaces all of that with a single bearer token, so global fetch is enough. See the auth details on how to authenticate the Reddit API and the Python version on how to use the Reddit API in Python.
Paging past the first page
One call returns 25 posts by default and 100 at most. To go further, read after from the response and send it straight back as a query parameter on the next request. When after comes back null the listing is exhausted, and that is the signal to stop rather than a page count you pick in advance.
let cursor = null;
const all = [];
while (true) {
const params = new URLSearchParams({
subreddit: "programming",
sort: "new",
limit: "100",
});
if (cursor) params.set("after", cursor);
const res = await fetch(
`https://api.redditapis.com/api/reddit/posts?${params}`,
{ headers: { Authorization: "Bearer YOUR_TOKEN" } },
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const page = await res.json();
all.push(...page.posts);
cursor = page.after;
if (!cursor) break; // listing exhausted, stop
}
console.log(`Collected ${all.length} posts`);Pass the cursor back exactly as you received it. It is an opaque string that also carries how deep into the listing you have walked, so a hand-built value from a Reddit fullname loses that and gives you a worse answer about where you are. Each request in the loop is billed the same $0.002, so ten pages of 100 posts is two cents.
What to do when a call fails
The example throws on any non-2xx, which is the right default for a script and the wrong one for a job you leave running. Some failures clear on their own and some never will, so a blanket retry is how a script burns an afternoon getting nowhere.
| Status | Meaning | Worth retrying |
|---|---|---|
| 402 | Out of credits | No. Add credit first, a retry loop will just repeat. |
| 403 | Invalid token | No. Fix the key. |
| 429 | Too many requests | Yes, after a pause. |
| 502 | Reddit was unreachable upstream | Yes, with backoff. |
Split those two groups in your catch block and the loop above survives a bad night upstream without hammering an endpoint that is never going to answer. Full details of what each call costs are on how much the Reddit API costs.
Frequently asked
How do I use the Reddit API in Node.js?
Use the built-in fetch to send a GET to api.redditapis.com with your bearer token in the Authorization header, then read the clean JSON with await res.json(). The response includes a posts array you can iterate.
Do I need a library like snoowrap?
No. Wrappers like snoowrap target the official Reddit OAuth API. Redditapis is a plain REST endpoint with a bearer token, so global fetch on Node 18 and up is enough, with no OAuth client to configure.
What does a Node.js read cost?
A GET read is $0.002 per call. You start with $0.50 in free credits, about 250 reads, so you can build and test your script before adding a card.
Does it work in the browser and edge runtimes?
The same fetch call works anywhere fetch is available, including edge and serverless runtimes. Keep the bearer token on the server side rather than shipping it to the browser.
Run this in Node.js in minutes
Grab a bearer token, drop it into the example, and start with $0.50 in free credits. No snoowrap, no OAuth.
Get your Reddit API key