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

@hammadxcm/hn-api-client-ts

v0.1.0

Published

Strict TypeScript client for the Hacker News Firebase API.

Readme

@hammadxcm/hn-api-client-ts (TypeScript)

npm version License: MIT Node TypeScript Coverage

Strict-mode TypeScript client for the Hacker News Firebase API. Discriminated-union Item types, typed errors, zero runtime dependencies. Part of the cross-language hacker-news-client suite.

Install

npm install @hammadxcm/hn-api-client-ts

Usage

import { HackerNewsClient, type Item, type Story } from '@hammadxcm/hn-api-client-ts';

const client = new HackerNewsClient();

const item = await client.item(1);
if (item?.type === 'story') {
  // item is narrowed to Story: item.title, item.url, item.score, ...
  console.log(item.title);
}

const top: Item[] = await client.topStories(10);
const tree = await client.commentTree(8863);
const user = await client.user('pg');

Type model

The Item union is tagged by a literal type field — TypeScript narrows on it:

import type { Item, Story, Comment, Job, Poll, PollOpt } from '@hammadxcm/hn-api-client-ts';

function describe(item: Item): string {
  switch (item.type) {
    case 'story':   return `story: ${item.title}`;
    case 'comment': return `comment on ${item.parent}`;
    case 'job':     return `job: ${item.title}`;
    case 'poll':    return `poll with ${item.parts.length} options`;
    case 'pollopt': return `option for poll ${item.poll}`;
  }
}

All fields are readonly and all optional fields use | undefined (with exactOptionalPropertyTypes: true enabled).

Configuration

new HackerNewsClient({
  baseUrl: 'https://hacker-news.firebaseio.com/v0',  // default
  timeout: 10_000,                                    // ms
  concurrency: 10,                                    // batch fan-out
  userAgent: 'my-app/1.0',
  fetch: customFetch,                                 // injectable typeof fetch
});

Errors

Typed error hierarchy:

import {
  HackerNewsClient,
  HackerNewsError,
  TimeoutError,
  HttpError,
  JsonError,
  TransportError,
} from '@hammadxcm/hn-api-client-ts';

try {
  await client.item(1);
} catch (err) {
  if (err instanceof HttpError) {
    // err.status and err.url are typed.
  }
}

Tests and dev

This package is developed directly from .ts sources using Node 22.6+'s --experimental-strip-types flag. No tsx or ts-node runtime is required.

cd ts
npm test             # 33 tests: 15 integration + 18 unit
npm run build        # tsc → dist/
npm run lint         # Biome (lint + format + import sort)

Coverage: 100% statements, branches, functions, and lines — measured via c8.

Full API

See the cross-language contract (DESIGN.md). Methods are camelCase, matching the JavaScript sibling.

Example

example.ts hits the live HN API:

npm run example
# or
node --experimental-strip-types --disable-warning=ExperimentalWarning example.ts

Links

License

MIT © hacker-news-client contributors. See LICENSE.