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

@carlosnc/discogs-sdk

v0.1.0

Published

A lightweight, fully-typed TypeScript client for the Discogs API

Readme

Discogs SDK

CI

A lightweight, fully typed TypeScript client for the Discogs API.

The project wraps the Discogs API v2 base URL, https://api.discogs.com/, with small namespace clients for the parts most useful to apps that search music metadata, inspect marketplace data, and read authenticated user data.

Status

This package is early-stage (0.1.0). It already covers the core read paths for:

  • database: search, releases, masters, master versions, artists, artist releases, labels, and label releases.
  • marketplace: listing details, release marketplace stats, price suggestions, and authenticated order reads.
  • inventory: user inventory reads.
  • user: identity, public profile, collection folders/items, lists, and wantlist.

The next planned work is tracked in BACKLOG.md.

Install

bun add @carlosnc/discogs-sdk

Node.js 18+ is supported because the default adapter uses global fetch.

Usage

import { DiscogsClient } from "@carlosnc/discogs-sdk";

const discogs = new DiscogsClient({
  token: process.env.DISCOGS_TOKEN!,
  userAgent: "my-app/1.0",
});

const results = await discogs.database.search({
  query: "Daft Punk Discovery",
  type: "release",
  perPage: 10,
});

console.log(results.results[0]?.title);

Public database lookup

const release = await discogs.database.getRelease(249504);

console.log(release.title);
console.log(release.artists[0]?.name);

Marketplace stats

const stats = await discogs.marketplace.getReleaseStats(249504);

console.log(stats.num_for_sale);
console.log(stats.lowest_price?.value, stats.lowest_price?.currency);

Marketplace orders

const orders = await discogs.marketplace.getOrders({
  status: "Payment Received",
  sort: "created",
  sortOrder: "desc",
  perPage: 10,
});

const order = await discogs.marketplace.getOrder(orders.orders[0]!.id);
const messages = await discogs.marketplace.getOrderMessages(order.id);

console.log(order.status);
console.log(messages.messages.length);

Collection fields

const fields = await discogs.user.getCollectionFields("carllosnc");

console.log(fields.fields.map((field) => field.name));

User lists

const lists = await discogs.user.getLists("discogs", { perPage: 5 });
const list = await discogs.user.getList(lists.lists[0]!.id);

console.log(list.name);
console.log(list.items[0]?.display_title);

Query parameter naming

SDK request params use TypeScript-friendly camelCase. The client converts them to the snake_case names expected by Discogs before sending the HTTP request.

| SDK param | Discogs query param | | --- | --- | | perPage | per_page | | sortOrder | sort_order | | releaseTitle | release_title |

Discogs params that are already short or lowercase, such as page, sort, query, type, catno, and barcode, keep the same name.

Pagination helpers

Use getNextPageParams when you want to request adjacent pages manually, or paginateDiscogs to iterate through every item from any paginated endpoint.

import { paginateDiscogs } from "@carlosnc/discogs-sdk";

for await (const release of paginateDiscogs(
  (params) => discogs.database.search({ query: "ambient", type: "release", ...params }),
  (page) => page.results,
  { perPage: 50 },
)) {
  console.log(release.title);
}

Abort and timeout

Every request accepts an AbortSignal through the low-level HTTP client. Use it for request timeouts or cancellation.

const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);

try {
  const response = await discogs.http.get("database/search", {
    params: { q: "Boards of Canada", type: "release", per_page: 5 },
    signal: controller.signal,
  });

  console.log(response.data);
} finally {
  clearTimeout(timeout);
}

Custom HTTP client

Use baseURL for tests, proxies, or mock servers while keeping the default fetch client.

const discogs = new DiscogsClient({
  baseURL: "https://proxy.example.com/discogs/",
});

You can also inject your own HttpClient for tracing, caching, or custom runtimes.

const discogs = new DiscogsClient({ httpClient });

Rate limits

Low-level HttpResponse objects expose Discogs rate-limit headers as response.rateLimit.

const response = await discogs.http.get("database/search", {
  params: { q: "Daft Punk", type: "release" },
});

console.log(response.rateLimit); // { limit, remaining, used }

Typed Discogs errors also expose error.rateLimit when the API includes those headers.

Authentication

Create a local .env from .env.example and set your personal Discogs token:

DISCOGS_TOKEN=your_discogs_token_here

Personal access tokens are sent as Authorization: Discogs token=...:

import { DiscogsClient } from "@carlosnc/discogs-sdk";

const discogs = new DiscogsClient({
  token: process.env.DISCOGS_TOKEN!,
  userAgent: "my-app/1.0",
});

const identity = await discogs.user.getIdentity();
console.log(identity.username);

For OAuth flows, pass a complete authorization header:

const discogs = new DiscogsClient({
  authHeader: "OAuth oauth_consumer_key=..., oauth_token=...",
  userAgent: "my-app/1.0",
});

Some public endpoints work without authentication, but authenticated requests are expected for identity, collection, wantlist, and inventory workflows.

Framework Adapters

The package exports convenience adapters for framework-specific usage:

import createDiscogsNextClient from "@carlosnc/discogs-sdk/nextjs";
import createDiscogsSvelteKitClient from "@carlosnc/discogs-sdk/sveltekit";

Development

bun install
bun run typecheck
bun test
bun run build
# optional: generate docs/api.md
bun run docs

Live tests use DISCOGS_TOKEN when it is present in the environment and are skipped otherwise.

Generated API docs are written to docs/api.md. Build output in dist/ is generated locally and intentionally not committed.

Runnable examples live in examples:

bun run examples/search.ts
bun run examples/barcode-search.ts
bun run examples/marketplace-stats.ts
bun run examples/collection-folders.ts
bun run examples/wantlist.ts
bun run examples/abort-timeout.ts

See CONTRIBUTING.md for branch, PR, validation, and release workflow notes.

API References