NRAW.js
Index
- Home
- Description
- How to
- Execute requests
- Users
- Subreddits
- Multireddits
- Comments
- Posts
- Voting
- Searching
- Random
- Queries
- Filters (User)
- Filters (Subreddit)
Description
NRAW.js simplifies the use of Reddit's API with an easy-to-use chainable functions.
How to
Start by installing NRAW.js:
$ npm install nraw
Then require it in your server:
var r = ;
Now, make a new instance of the r
-object, which you can do by providing a User-agent.
var Reddit = "Testbot v0.0.1 by Mobilpadde";
Or you can fill in three parameters, which are a user-agent, a cookie and the modhash of a Reddit user:
var Reddit = "Testbot v0.0.1 by Mobilpadde" cookie modhash;
Execute requests
Executing requests can be done in two ways:
Reddit
Or
Reddit
In the examples below, the first method will be applied.
User
Get the 25 latest posts (Links, self-posts or comments) of a given user:
Reddit
"That's stupid! Who'd ever need the latest 25 posts of a user?", you say? Well, NRAW.js is smart enough to handle queries too!
Let's make a basic request that gets the top five posts (Links, self-posts and comments) of a user:
Reddit
Pretty cool, 'eh?
"But what if I want to see seven of my liked posts and comments?" - That's super easy too! Simply use the login
-function and the liked
-filter:
Reddit
Subreddit
Get the 25 latest posts (Links and self-posts) of a given subreddit:
Reddit
"That's not useful at all! I hate you" - You.
Well, like last time, we have queries that can be applied, but wait! There's more! Subreddits even have the ability to be filtered!
Let's make a request of the 25 most controversial posts from the last year from a given subreddit, but only the ones after the post with the id t3_2k0r3o
:
Reddit
Or how about we make a request, that finds the 42 top comments of a given subreddit, using the filter comments
:
Reddittop
"Can I get a single post if I know its id?" - Easy peasy!
Reddit
"Whoa, that's pretty awesome, but can I post a link?" - Of course you can! We just need to login and use the post
-function:
Redditlink"How I feel when there's only one pizza slice left" "http://i.imgur.com/CFSwHdq.gif"
"Wow! C-c-can I subscribe to subreddits then?" - Yea you can! Though we'll have to get our hands a bit dirty:
Reddit
"Awesome! But what if I don't like a subreddit anymore?" - Well, that's a bit tougher! Ha! Gotcha! You should've seen your face! Priceless! Don't worry, it's super easy too:
Reddit
We can even search through a subreddit:
Reddit
"What if I want a random thread from a given subreddit?" - Pure easiness! Simply do:
Reddit
Multireddits
You can also get multireddits:
Reddit
Comments
How about we play around with some comments for a while?
Let's get all the new comments (Login so we don't have to wait 30 seconds before we can request new comments):
Reddit
"Well, now for a tough one! Can I post comments?" - Yes! Yes you can! All you need is an id of the parent (In this case we're gonna use t3_31cvo9
):
Reddit
"What if I want to see a specific comment and I have its id?" - Well, that's super easy like everything else:
Reddit
"I want to delete my comment, please help!" - Alrighty! It's as easy as pie:
Reddit
Posts
You can also delete a post if you misspelled something:
Reddit
"But I want the related posts of a post to which I know the id" - That's even easier! Take a look at this:
Reddit
Voting
Upvoting:
Reddit
Unvoting:
Reddit
Downvoting:
Reddit
Ps. add .comment("t1_coestfz")
, if you want to vote on a comment instead of a post.
Searching
You can also search for every thread - in every subreddit - containing the word cat
:
Reddit
Random
How 'bout getting a random thread, you say?
Reddit
Queries
- after - postId
- before - postId
- count - 1- 100
- limit - 1 - 100
- from - "hour", "week", "month", "year", "all"
- sort - "hot", "top", "new", "controversial"
Filters (User)
- comments
- disliked
- hidden
- liked
- overview
- saved
- submitted
Filters (Subreddit)
- comments
- controversial
- hot
- gilded
- new
- promoted
- rising
- top