skip to content

What does an npm registry's packument contain, and how do its dist-tags and dist fields lead a client to the tarball?

level: middleimportance: must knowfreq 55%

answer

  1. one JSON document per package
  2. labels that point at versions
  3. a dist object per version
  4. tarball URL plus integrity
  5. document edited, tarballs never

basics

~20 s

An npm packument is the registry's JSON document for one package: dist-tags map labels such as latest to version numbers, versions holds each version's manifest, and each manifest's dist object gives the tarball URL and its integrity hash.

solid answer

~40 s

The packument is what the registry returns for a package name. Its `dist-tags` map labels to version numbers; publishing moves `latest` unless another tag is given, and installing a bare package name picks the `latest` version. `versions` maps each version number to that version's manifest, and every manifest carries a `dist` object: `tarball` (the `.tgz` URL, such as `https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz`), `shasum`, `integrity` (a Subresource Integrity string, `sha512` or `sha1`) and, on registries that sign, `signatures`. `time` records when each version was published. The packument is mutable, since dist-tag moves and deprecations rewrite it, while a published tarball is not, and on the public registry a `name@version` once used can never be used again, even after an unpublish.

code

json · 21 lines
json
{
  "name": "invoice-utils",
  "dist-tags": {
    "latest": "1.4.0",
    "next": "2.0.0-rc.1"
  },
  "versions": {
    "1.4.0": {
      "name": "invoice-utils",
      "version": "1.4.0",
      "dist": {
        "tarball": "https://registry.example.com/invoice-utils/-/invoice-utils-1.4.0.tgz",
        "shasum": "<sha1 hex>",
        "integrity": "sha512-<base64 digest>"
      }
    }
  },
  "time": {
    "1.4.0": "2026-09-30T10:12:00.000Z"
  }
}

go deeper

for a junior

Recall that the registry serves one JSON document per package, with dist-tags naming versions and each version pointing at its tarball.

for a middle

Walk through how a client turns latest or a range into one version's dist.tarball and verifies it with dist.integrity, and say which fields change after publish.

for a senior

Debug wrong or failed installs by reading the packument the client actually received: a missing version entry, a moved dist-tag or metadata blocked by permissions while the tarball is reachable.

for a principal

Decide which identities may move dist-tags on internal packages, since a tag move changes what every unpinned install gets without any new artifact being published.

## One index document, many tarballs An npm registry serves two kinds of object for every package: - **The packument**, one JSON document per package name, which describes every version the registry holds. - **The tarballs**, one `.tgz` file per published version, holding the package's files. A client never guesses a tarball's location. It fetches the packument, picks a version, and follows the URL that the packument gives for that version. That makes the packument the thing to read first when an install picks the wrong version or cannot find one. ## The fields that matter | Field | What it holds | Who changes it | |---|---|---| | `name` | the package name | set at first publish | | `dist-tags` | labels mapped to version numbers, such as `latest` and `next` | every publish (moves `latest` unless another tag is given), dist-tag commands | | `versions` | a map from version number to that version's manifest | each publish adds one entry; deprecation edits an entry | | `versions[v].dist` | `tarball`, `shasum`, `integrity`, optionally `signatures` | written at publish | | `time` | publish timestamps keyed by version | the registry | Inside `dist`: - **`tarball`** is the download URL. On the public registry it has the shape `https://registry.npmjs.org/<name>/-/<name>-<version>.tgz`. - **`integrity`** is a Subresource Integrity string, normally `sha512-...` (the format also allows `sha1`), that the client checks the downloaded tarball against. - **`shasum`** is the older SHA-1 hex digest. - **`signatures`**, where the registry signs, holds a `keyid` and `sig` over `${name}@${version}:${integrity}`; the registry publishes its public keys at `/-/npm/v1/keys`. ## How a client walks the packument 1. Fetch the packument for the package name from the configured registry. 2. Turn the requested specifier into a version. A tag such as `latest` or `beta` is looked up in `dist-tags`; a bare package name means `latest`; a range is matched against the keys of `versions`. 3. Read that version's `dist.tarball` and download it. 4. Verify the bytes against `dist.integrity`, and, where present, the registry signature. Steps 2 and 4 depend entirely on what the document says, which is why a stale or partial packument produces a wrong install even when every tarball is present. ## What changes and what never does - **Dist-tags are mutable.** Moving `latest` back to an older version rewrites one entry in `dist-tags`; no tarball is re-uploaded and no hash changes. - **Deprecation edits the document.** The CLI fetches the packument, sets a `deprecated` message on the chosen entries in `versions`, and writes it back. The tarball is untouched, so the version still installs, with a warning. - **Version numbers are not reusable.** The public registry's unpublish policy says that once `package@version` has been used it can never be used again, even after an unpublish. A fix ships as a new version. - **Tags cannot look like ranges.** A tag that semver could read as a range, such as `v1.4`, is rejected, because tags and versions share the same slot in `<name>@<spec>`. ## Reading a packument when an install goes wrong 1. Fetch the packument through the **same URL** the build uses, including any group or virtual repository in front of the registry. 2. Check that the version you expect is a key under `versions`; if it is missing, no specifier can select it. 3. Check what each relevant label in `dist-tags` points at, since an unpinned install follows `latest`. 4. Request the `dist.tarball` URL of the chosen version and confirm it returns the file. 5. Hash the download and compare it with `dist.integrity`; a mismatch means the bytes are not the ones published. ## How a repository manager serves npm A repository manager hosting npm stores the tarballs you publish and **generates the packument** from them; Artifactory, for example, documents calculating metadata for packages in its local repositories. Two things follow for operators: - In Artifactory the packument is stored and permissioned **separately** from the tarball: npm metadata lives under `.npm/<repo>/<package>` paths, so a permission whose include patterns cover only `<repo>/<package>/**` lets the tarball through and makes the metadata request fail. - A proxy of the public registry caches packuments and tarballs on separate terms; how long a cached packument may be served before it goes stale is a proxy setting, not a property of the format. ## Common misreadings - Treating `dist-tags` as a list of all versions; it holds only labels. - Expecting a dist-tag move or a deprecation to touch tarballs. - Assuming an unpublished version number is free to reuse on the public registry. - Reading `integrity` as a hash of the packument rather than of the tarball.

  • In Artifactory, why can a user download an npm tarball yet get an error requesting the same package's metadata from a virtual repository?
    Artifactory keeps npm package metadata under `.npm/<repo>/<package>` paths, separate from the tarball's path. A permission whose include patterns cover only `<repo>/<package>` and `<repo>/<package>/**` admits the tarball but not the metadata. The documented fix adds `.npm/<repo>/<package>` and `.npm/<repo>/<package>/**`, with the `@<scope>` segment for scoped packages.
  • What does deprecating an npm version change in the registry?
    Only the packument. The CLI fetches the document, sets a `deprecated` message on each matching entry under `versions`, and writes the document back. No tarball is touched, so the deprecated version still installs and clients show the message as a warning.
  • Why does the npm registry reject a dist-tag named v1.4?
    Tags and versions occupy the same slot in `<name>@<spec>`, so a tag that semver can parse as a range would be ambiguous: `v1.4` reads as `>=1.4.0 <1.5.0`. Tags that parse as ranges are rejected, and the docs advise tags that do not start with a digit or the letter `v`.

  • dist-tags list every version that has been published.
  • Moving the latest tag re-uploads the older version's tarball.
  • Clients build the tarball URL themselves, so dist.tarball is decoration.
  • Unpublishing a version frees its number for a corrected re-publish.
  • The integrity field is a hash of the packument itself.