Wondering what’s next for npm?Check out our public roadmap! »

    simple-reddit-api
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    simple-reddit-api

    Simple client for the reddit public api. (No auth needed)

    Get it from npm

    npm i simple-reddit --save

    Import

    const Reddit = require("simple-reddit");

    or just import individual functions.

    const {topPost} = require("simple-reddit");

    Usage

    Basic examples:

    Get top post from reddit.

    RedditSimple.topPost(options).then(res => {
        console.log(res);
    })

     

    Get new post from reddit.

    RedditSimple.newPost(options).then(res => {
        console.log(res);
    })

     

    Get random post from reddit.

    RedditSimple.randomPost(options).then(res => {
        console.log(res);
    })

     

    Search if a subreddit exists.

    RedditSimple.searchSubreddits('dankmemes').then(res => {
        console.log(res);
    })
    • Args: Name of subreddit to be searched. (Required)

     

    Get popular subreddits.

    RedditSimple.popularSubreddits(count).then(res => {
        console.log(res);
    })
    • Args: Number of subreddits to be displayed. (Defaults to 1)

    Options

    There are 4 options that you can pass.

    Name Value Description Default
    subreddit name of subreddit Subreddit to fetch the post. r/all
    count Number of posts to retrieve Retrieves n number of posts. 1 (max:100)
    is_meme true/false If you want to get a meme. Ignores subreddit option if true. false
    fulldata true/false Retrieve essential post data or everything reddit has to offer. false

    Values returned from the method

    Post details

    {
        status:200/404, //404 if any error occurs
        posts:[ //empty incase of error/no subreddit
            {
                data: {
    		        title: string,
    		        author: string,
    		        subreddit_name_prefixed: string,
    		        ups: number,
    		        total_awards_received: number,
    		        url: string,
    	        }
            } //Incase of fulldata:true, posts array has the raw post object returned by reddit
        ]
    }

    Search subreddits

    {
    	status: 200/404, //404 if any error occurs
    	subreddit: subreddit,
    	url: `${api}${subreddit}`
    }

    List subreddits

    {
        status:200/400, //404 if any error occurs
        subreddits:[  //array empty in case of error
            {
                data: {
    		        display_name_prefixed: string,
    		        subscribers: string,
    		        description: string,
    		        url: string
                }
            }
        ]
    }

    Install

    npm i simple-reddit-api

    DownloadsWeekly Downloads

    4

    Version

    2.0.1

    License

    ISC

    Unpacked Size

    25.3 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar