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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-hn-api

v4.0.1

Published

A modern TypeScript wrapper for the Firebase Hacker News API with full type support and promise-based methods

Downloads

32

Readme

node-hn-api

Build Status npm PRs Welcome

A modern TypeScript wrapper for the Firebase Hacker News API with full type support and promise-based methods.

Features

  • Promise-based API with full TypeScript support
  • Fetch individual items, users, and various story categories
  • Built-in error handling and type safety
  • Works in both Node.js and browser environments
  • Supports both CommonJS and ES modules
  • Zero runtime dependencies - uses native fetch API

Installation

npm install node-hn-api
# or
pnpm add node-hn-api
# or
yarn add node-hn-api

Quick Start

CommonJS

const hn = require('node-hn-api');

hn.fetchTopStories(5)
  .then((stories) => {
    console.log('Top 5 stories:', stories);
  })
  .catch((error) => {
    console.error('Error fetching stories:', error);
  });

ES Modules / TypeScript

import { fetchTopStories, fetchItem, fetchUser } from 'node-hn-api';

// Fetch top stories
const stories = await fetchTopStories(10);
console.log('Top 10 stories:', stories);

// Fetch a specific item
const item = await fetchItem(8863);
console.log('Item details:', item);

// Fetch user information
const user = await fetchUser('pg');
console.log('User details:', user);

API Reference

This library provides TypeScript-friendly functions with full type definitions. All functions return promises and include comprehensive JSDoc comments for excellent IDE support.

Core Functions

// Fetch individual items and users
fetchItem(itemId: number): Promise<HackerNewsItem>
fetchUser(userId: string): Promise<HackerNewsUser>

// Fetch different story types (all with optional numberOfStories parameter, default: 10)
fetchTopStories(numberOfStories?: number): Promise<HackerNewsItem[]>
fetchNewStories(numberOfStories?: number): Promise<HackerNewsItem[]>
fetchBestStories(numberOfStories?: number): Promise<HackerNewsItem[]>
fetchAskStories(numberOfStories?: number): Promise<HackerNewsItem[]>
fetchShowStories(numberOfStories?: number): Promise<HackerNewsItem[]>
fetchJobStories(numberOfStories?: number): Promise<HackerNewsItem[]>

Type Definitions

The library exports HackerNewsItem and HackerNewsUser interfaces with complete type definitions. Your IDE will provide full IntelliSense support showing all available properties and their types.

Basic Examples

// Fetch a story and its author
const story = await fetchItem(8863);
const author = await fetchUser(story.by);
console.log(`"${story.title}" by ${author.id} (${author.karma} karma)`);

// Get top stories
const topStories = await fetchTopStories(10);
console.log(topStories.map(s => `${s.title} (${s.score} points)`));

// Error handling
try {
  const user = await fetchUser('username');
  console.log(`User has ${user.submitted.length} submissions`);
} catch (error) {
  console.error('User not found:', error.message);
}

For detailed parameter information, return types, and additional examples, rely on your IDE's IntelliSense or view the generated type definitions.

Requirements

  • Node.js 18.0.0 or higher (for native fetch support)
  • Modern browsers (all browsers support fetch natively)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Arjun Sajeev

Related