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

product-hunt

v0.5.0

Published

Unofficial wrapper of the public product hunt API.

Downloads

13

Readme

Product Hunt

NPM Version Build Status Coverage Status

Unofficial wrapper of the public Product Hunt API.

Product Hunt

Installation

npm i -S product-hunt

Interface

The module exposes a couple of methods to build a request Object which can be executed in order to retrieve products, i.e. posts, from Product Hunt.

This is done by using one of the category specific request builder methods.

| Request Builder Method | Category | Default | | --- | --- | --- | | popular | type | yes | | newest | type | no | | today | timeframe | yes | | yesterday | timeframe | no | | daysAgo | timeframe | no |

After building the request Object, it can be executed by using the .exec() method. This returns a Promise which resolves with the retrieved products.

When using multiple methods of the same category, the last invoked method is used to build the request Object.

Syntax

productHunt
  .popular()
  .today()
  .exec()
  .then()
  .catch();

Methods

After requiring the module, the following methods can be used:

| Method | Arguments | Returns | Description | | --- | --- | --- | --- | | popular | no | Object | retrieve the most popular products | | newest | no | Object | retrieve the newest products | | today | no | Object | retrieve todays products | | yesterday | no | Object | retrieve yesterdays products | | daysAgo | yes | Object | retrieve products from n days ago | | exec | no | Promise | execute a built request |

.popular()

Request builder method used to retrieve the most popular products from Product Hunt.

| Query Builder Method | Category | Default | | --- | --- | --- | | yes | type | yes |

Arguments

None.

Returns

productHunt Object which can be executed with the .exec() method.

.newest()

Request builder method used to retrieve the newest products from Product Hunt.

| Query Builder Method | Category | Default | | --- | --- | --- | | yes | type | no |

Arguments

None.

Returns

productHunt Object which can be executed with the .exec() method.

.today()

Request builder method used to retrieve todays products from Product Hunt.

| Query Builder Method | Category | Default | | --- | --- | --- | | yes | timeframe | yes |

Arguments

None.

Returns

productHunt Object which can be executed with the .exec() method.

.yesterday()

Request builder method used to retrieve yesterdays products from Product Hunt.

| Query Builder Method | Category | Default | | --- | --- | --- | | yes | timeframe | no |

Arguments

None.

Returns

productHunt Object which can be executed with the .exec() method.

.daysAgo(n)

Request builder method used to retrieve Product Hunt products from n days ago.

0 denotes today, 1 denotes yesterday, etc.

| Query Builder Method | Category | Default | | --- | --- | --- | | yes | timeframe | no |

Arguments

| Name | Type | Required | Description | | --- | --- | --- | --- | | n | Number | yes | The number of days in the past. Must be 0 or greater.

Returns

productHunt Object which can be executed with the .exec() method.

.exec()

Executes the built request.

After executing the productHunt Object, the built request Object will be reset, meaning it will default to popular and today again.

Arguments

None.

Returns

Promise that resolves with a products Array, where each element is a product Object.

Product Object (Post) Representation

{
  "id": 62330,
  "category_id": 1,
  "slug": "li-st",
  "user_id": 187835,
  "name": "li.st",
  "comment_count": 5,
  "tagline": "Create lists about anything, by B.J. Novak & Devin Flaherty",
  "topics": [
    {
      "id": 2,
	  "name": "Android",
	  "slug": "android",
	  "trending": false
	},
	{
      "id": 8,
	  "name": "iPhone",
	  "slug": "iphone",
	  "trending": false
	}
  ],
  "created_at": "2016-05-11T11:10:05.558-07:00",
  "featured_at": "2016-05-12T00:01:00.000-07:00",
  "url": "/tech/li-st",
  "shortened_url": "/r/611d59ec8d02e8/62330",
  "vote_count": 51,
  "product_state": "default",
  "category": {
    "has_upcoming": true,
    "id": 1,
    "slug": "tech",
    "name": "Tech",
    "item_name": "product",
    "color": "#5898f1"
  },
  "exclusive": null,
  "user": {
    "id": 187835,
    "username": "bjnovak",
    "name": "B.J. Novak",
    "headline": "",
    "image_urls": {
      "60": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=60&h=60",
      "160": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=160&h=160"
    },
    "link": "/@bjnovak",
    "avatar_url": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=160&h=160",
    "is_maker": true
  },
  "thumbnail": {
    "id": 163210,
    "kindle_asin": null,
    "media_type": "image",
    "platform": null,
    "video_id": null,
    "url": null,
    "image_url": "https://ph-files.imgix.net/c02512f1-525b-42a8-8737-10cee482368f?auto=format&fit=max&h=570&w=430"
  },
  "shortened_link": "611d59ec8d02e8",
  "author": {
    "id": 187835,
    "username": "bjnovak",
    "name": "B.J. Novak",
    "headline": "",
    "image_urls": {
      "60": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=60&h=60",
      "160": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=160&h=160"
    },
    "link": "/@bjnovak",
    "avatar_url": "https://ph-avatars.imgix.net/187835/original?auto=format&fit=crop&crop=faces&w=160&h=160",
    "is_maker": true
  },
  "category_slug": "tech",
  "is_featured": true
}

Example 1

Fetch yesterdays newest products:

'use strict';

const productHunt = require('product-hunt');

const request = productHunt
  .newest()
  .yesterday();

const getProductsPromise = request.exec();

getProductsPromise
  .then(function productsFetcher(products) {
    console.log('products: ', products);
  })
  .catch(function errorHandler(err) {
    console.log('err: ', err.message);
  });

Example 2

Fetch the most popular products of 3 days ago:

'use strict';

const productHunt = require('product-hunt');

productHunt
  .popular()
  .daysAgo(3)
  .exec()
  .then(console.log.bind(console))
  .catch(console.error.bind(console));

Example 3

Fetch todays most popular products by using default behavior:

'use strict';

const productHunt = require('product-hunt');
const co = require('co');

function todayPopularProducts() {
  return co(function *fetchProducts() {	  
    const products = yield productHunt.exec();

    console.log(`products: ${products}`);
  });
}

todayPopularProducts();

When no other methods besides the exec() method are provided. The default behavior is to retrieve the most popular products of today.

Example 4

Using multiple methods of the same category:

'use strict';

const productHunt = require('product-hunt');
const co = require('co');

function todayPopularProducts() {
  return co(function *fetchProducts() {	  
    const products = yield productHunt
	  .newest()
	  .yesterday()
	  .daysAgo(4)
	  .today() // last used `timeframe` method
	  .popular() // last used `type` method
	  .exec();

    console.log(`products: ${products}`);
  });
}

todayPopularProducts();

When using multiple methods of the same category, the last invoked method is used to build the request Object. Therefore this example will result in fetching todays most popular products.