npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hnfavs

v0.0.12

Published

<img src="img.png" alt="alt text" width="600">

Downloads

3

Readme

hacker-news-favorites-api

A simple script that will scrape the favorites for a provided hacker news user id.

BeforeAfter 👍

Why?

The official Hacker News API from Y Combinator doesn't include the favorites endpoint. I use favorites like bookmarks and wanted to sync them to another app.

Usage

You can run yourself, or use the api endpoint hosted at the below url. Be sure to pass the query params mentioned below.

Base Endpoint:

https://reactual.api.stdlib.com/hnfavs/

Example URL:

This example would download 1 page of 30 favorites for the user sbr464

https://reactual.api.stdlib.com/hnfavs/?id=sbr464&limit=1


Accepts 3 query params, only id is required.

id

required | string | default='' | The Hacker News username.

limit

optional | number | default=1 | Max # of pages to download (30/page).

offset

optional | number | default=1 (none) | Pagination offset, the page to begin on.


Data Format

The API will return a JSON object-array containg the favorites as below. You can use the article id to obtain more info via the Hacker News API. There is more info (comments link, score) avail to scrape from favorites, but the HN API is more reliable.

;[
  {
    // HN article id
    id: '17437185',

    // Article's direct url (not comments)
    link: 'https://github.com/serhii-londar/open-source-mac-os-apps',

    // Title of the article on HN
    title: 'Awesome macOS open source applications'
  }
]

Notes

Currently, the request timeout is manually set to just under 3 minutes, but could change. You may need to provide an offset and make multiple requests if you are getting a timeout when trying to download hundreds-thousands+ of favorites. If you receive a timeout error, modify the limit/offset and retry the request. We are using stdlib to host the api.

More Info

Additional docs & a live testing tool avail at stdlib.

Installation via npm

Recently published as hnfavs on npm, have only done basic testing. x-ray is a required peer dependency, you'll need to add to your project.

npm install --save hnfavs x-ray

yarn add hnfavs x-ray
// Basic usage
const hnfavs = require('hnfavs')

hnfavs('sbr464').then(console.log)

Local Installation

It's a node.js app, using x-ray for the web scraping. See src/main.test.js for example usage locally.

# Clone repo
$ git clone [email protected]:reactual/hacker-news-favorites-api.git

$ cd hacker-news-favorites-api

# Install with yarn or npm
$ yarn

# Run tests
$ yarn test