Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

query-registry

velut62.2kMIT4.0.0TypeScript support: included

Query the npm registry for packuments, manifests, packages and download counts

query, registry, npm, client, api, packument, package, downloads, search, manifest, typescript

readme

query-registry

Build status Coverage jsDocs.io Language npm License

query-registry is an API wrapper for the npm registry API.

Features

  • Provides functions to:
    • Get registry metadata.
    • Get registry public keys.
    • Get packuments (package documents) with full package metadata.
    • Get abbreviated packuments with installation data only.
    • Get package manifests for each version of a package.
    • Get download counts for the registry and for packages.
    • Search packages by name and other specific criteria.
  • Works in the browser.
  • Validates registry responses with zod.
  • Automatically caches registry responses for a short time.
  • Supports third-party npm-compatible registries.

Useful resources

Install

Using npm:

npm add query-registry

Using yarn:

yarn add query-registry

Using pnpm:

pnpm add query-registry

Using bun:

bun add query-registry

Usage examples

Registry

Get the metadata about the npm registry itself, if available:

import { getRegistryMetadata } from "query-registry";

const metadata = await getRegistryMetadata();

Get the public signing keys for the npm registry:

import { getRegistrySigningKeys } from "query-registry";

const { keys } = await getRegistrySigningKeys();

Packuments (Package documents)

Get the abbreviated packument containing only the necessary data to install the react package:

import { getAbbreviatedPackument } from "query-registry";

const abbrPackument = await getAbbreviatedPackument("react");

Get the full packument containing all the data available about the react package:

import { getPackument } from "query-registry";

const packument = await getPackument("react");

Package manifests

Get the manifest containing the original package.json data plus additional registry metadata for the latest version of the react package:

import { getPackageManifest } from "query-registry";

const manifest = await getPackageManifest("react");

Get the manifest for `react@18.2.0` (semver version):

import { getPackageManifest } from "query-registry";

const manifest = await getPackageManifest("react", "18.2.0");

Get the manifest for react@next (distribution tag):

import { getPackageManifest } from "query-registry";

const manifest = await getPackageManifest("react", "next");

Search packages

Search packages related to react (e.g., react, react-dom, ...):

import { searchPackages } from "query-registry";

const results = await searchPackages({ text: "react" });

Download counts

Get the total number of downloads for package react for the last month:

import { getPackageDownloads } from "query-registry";

const { downloads } = await getPackageDownloads("react", "last-month");

There are also these other download counts functions available: getBulkDailyPackageDownloads, getBulkPackageDownloads, getDailyPackageDownloads, getDailyRegistryDownloads and getPackageVersionsDownloads.

Cache

Clear the internal cache.

import { cache } from "query-registry";

cache.clear();

See the quick-lru package for the cache API.

License

MIT

Copyright (c) 2025 Edoardo Scibona

See LICENSE file.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

  • None

4.0.0 - 2025-01-20

Changed

  • BREAKING CHANGE: Updated the SearchCriteria and SearchResult types used with the searchPackages() function to align with the latest npm registry requirements and responses
  • Upgraded dependencies

3.0.1 - 2024-06-12

Changed

3.0.0 - 2024-04-23

Version 3 is a complete rewrite of query-registry.

This package is now a pure ESM package and uses the fetch global function to perform network requests.

Additionally, every response returned by the registry is now validated against its expected schema. This means that data can now be safely accessed according to the corresponding TypeScript type definition. Unexpected data will reject with an error; in this case open an issue to propose changes to the schemas.

Added

These are the current package's exports:

  • Variables:
    • cache
    • npmRegistryDownloadsApiUrl
    • npmRegistryUrl
  • Functions:
    • getAbbreviatedPackument()
    • getBulkDailyPackageDownloads()
    • getBulkPackageDownloads()
    • getDailyPackageDownloads()
    • getDailyRegistryDownloads()
    • getPackageDownloads()
    • getPackageManifest()
    • getPackageVersionsDownloads()
    • getPackument()
    • getRegistryDownloads()
    • getRegistryMetadata()
    • getRegistrySigningKeys()
    • searchPackages()
  • Zod schemas / TypeScript types:
    • AbbreviatedPackument
    • BulkDailyPackageDownloads
    • BulkPackageDownloads
    • DailyPackageDownloads
    • DailyRegistryDownloads
    • DownloadPeriod
    • PackageDownloads
    • PackageJson
    • PackageManifest
    • PackageVersionsDownloads
    • Packument
    • RegistryDownloads
    • RegistryMetadata
    • RegistrySigningKeys
    • SearchCriteria
    • SearchResults

Changed

  • BREAKING CHANGE: This package is now a pure ESM package.
  • BREAKING CHANGE: Require Node.js 20 (latest LTS).
  • BREAKING CHANGE: Use fetch for network requests.

2.6.0 - 2022-08-13

Added

  • Added custom normalization for git urls; the normalized values for the gitRepository property may change with respect to previous releases.

Changed

  • Updated dependencies and dev dependencies.

Removed

  • Removed dependency on git-url-parse.

2.5.0 - 2022-05-28

Changed

  • Fixed ESM export declarations in package.json (Thanks @mt-empty).
  • Updated dependencies and dev dependencies.

2.4.0 - 2022-05-11

Changed

  • Preserve subdomains in git repository URLs (https://git.example.com/user/repo) (Thanks @tomdyqin).
  • Updated dependencies and dev dependencies.

2.3.0 - 2022-04-27

Changed

  • Preserve pathnames in registry URLs (https://example.com/my/npm/registry) (Thanks @tomdyqin).
  • Updated dependencies and dev dependencies.

2.2.0 - 2021-12-01

Added

  • Abbreviated packuments (application/vnd.npm.install-v1+json) can now be retrieved using getAbbreviatedPackument() or getRawAbbreviatedPackument().

Changed

  • Responses are now cached based on headers and URL.
  • Updated docs.
  • Updated dependencies and dev dependencies.
  • Moved debug package to dev dependencies.

2.0.0 - 2021-03-09

Added

  • BREAKING CHANGE: Added export map to package.json.
  • Export named functions to query the npm registry:
    • getDailyPackageDownloads()
    • getDailyRegistryDownloads()
    • getPackageDownloads()
    • getPackageManifest()
    • getPackument()
    • getRawPackageManifest()
    • getRawPackument()
    • getRegistryDownloads()
    • getRegistryMetadata()
    • searchPackages()
  • This package can now be used in a browser environment.

Changed

  • Updated typing of registry responses.
  • Updated normalization of custom properties on Packument and PackageManifest interfaces.
  • Updated and reduced number of dependencies.

Removed

  • BREAKING CHANGE: Removed Registry class; use the exported functions instead.