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

bgg-api-ts

v1.0.0

Published

A type-safe TypeScript SDK for the BoardGameGeek XML API v2

Readme

bgg-api-ts

A TypeScript wrapper for the BoardGameGeek XML API v2. The BGG API speaks XML; this library handles that and gives you typed objects back.

Installation

npm install bgg-api-ts

Requirements

BGG requires an API token as of 2025. Register an application, then generate a token from your application page.

Do not make requests from a browser. Your token will be exposed. Run this server-side.

Quick Start

import { BggClient } from "bgg-api-ts";

const client = new BggClient("https://boardgamegeek.com/xmlapi2/", "your-api-token");

const result = await client.getThing(174430, { stats: true });
const game = result.items.item[0];

console.log(game.name[0].value); // "Gloomhaven"
console.log(game.statistics?.ratings.average.value); // 8.4

Authentication

Pass your token as the second argument to BggClient:

const client = new BggClient("https://boardgamegeek.com/xmlapi2/", process.env.BGG_TOKEN);

The token is sent as a Bearer header on every request. See the Installation & Auth wiki page for setup steps.

Rate Limiting

The client waits at least 5 seconds between requests automatically. You do not need to manage this yourself. Sending requests faster than that causes BGG to return 500 or 503 errors.

Error Handling

Two error types are thrown:

  • BggError: HTTP errors (401, 403, 429, 500, 503). Has a statusCode property.
  • BggTimeoutError: The request took longer than 30 seconds, or the server returned HTTP 202 (queued) more than 5 times in a row.
import { BggClient, BggError, BggTimeoutError } from "bgg-api-ts";

try {
  const result = await client.getCollection({ username: "someuser", own: true });
} catch (err) {
  if (err instanceof BggTimeoutError) {
    // BGG queued the request and never finished processing it
    console.error("Timed out:", err.message);
  } else if (err instanceof BggError) {
    // HTTP error from BGG
    console.error(`HTTP ${err.statusCode}:`, err.message);
  }
}

HTTP 202 is specific to the collection endpoint. BGG queues those requests when the data is not cached. The client retries up to 5 times before giving up.

Examples

Fetch a game with stats

const result = await client.getThing(174430, { stats: true });
const game = result.items.item[0];

console.log(game.name[0].value); // "Gloomhaven"
console.log(game.statistics?.ratings.ranks.rank[0].value); // 1

Fetch multiple games at once

const result = await client.getThing([174430, 161936, 167791]);

for (const item of result.items.item) {
  console.log(item.id, item.name[0].value);
}

Search for a game

const result = await client.search({ query: "Catan", type: "boardgame", exact: true });
const id = result.items.item?.[0].id; // 13

Get a user's owned games

const result = await client.getCollection({ username: "Blxckmage", own: true, stats: true });

console.log(result.items.totalitems); // number of owned games
for (const item of result.items.item ?? []) {
  console.log(item.name[0].value);
}

Get play history

const result = await client.getPlays({ username: "Blxckmage", mindate: "2025-01-01" });

console.log(result.plays.total); // total plays logged
for (const play of result.plays.play ?? []) {
  console.log(play.date, play.item[0].name);
}

Get the hot list

const result = await client.getHot("boardgame");

for (const item of result.items.item) {
  console.log(item.rank, item.name?.value);
}

API Reference

Full parameter and response type documentation is on the GitHub Wiki.

| Method | Description | |---|---| | getThing(ids, options?) | Fetch games, expansions, or accessories by ID | | getFamily(ids, type?) | Fetch game family groups by ID | | getHot(type) | Fetch the current hot list for a category | | search(options) | Search by name | | getUser(options) | Fetch a user profile | | getCollection(options) | Fetch a user's game collection | | getPlays(options?) | Fetch play history |

Terms of Use

This library accesses the BGG XML API. Use of the API is subject to the BGG XML API Terms of Use:

  • Non-commercial use only, unless you have a license from BGG.
  • Data from the API cannot be used to train AI or LLM systems.
  • You must credit BoardGameGeek by name and include a "Powered by BGG" logo where applicable.
  • You must link back to BoardGameGeek.

License

MIT