Socket
Socket
Sign inDemoInstall

simple-reddit-api

Package Overview
Dependencies
7
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-reddit-api

A simple reddit api that doesnt require auth.


Version published
Maintainers
1
0
Install size
506 kB

Weekly downloads

Readme

Source

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)

 

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.

NameValueDescriptionDefault
subredditname of subredditSubreddit to fetch the post.r/all
countNumber of posts to retrieveRetrieves n number of posts.1 (max:100)
is_memetrue/falseIf you want to get a meme. Ignores subreddit option if true.false
fulldatatrue/falseRetrieve 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
            }
        }
    ]
}

Keywords

FAQs

Last updated on 29 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc