Skip to the content.

npm, Yarn, pnpm, Bun

Point the JavaScript package managers at the proxy’s npm upstream instead of registry.npmjs.org. The examples use the upstream name npm; replace it with the name your operator gave the upstream (what you need).

   
Upstream type npm
Package source https://proxy.example.com/v1/npm/
Clients npm, Yarn 1, Yarn 2 and later, pnpm, Bun
Tested npm 10.9: in CI on every push and in the client lab. Yarn 1.22, Yarn 4.5, pnpm 9.15, Bun 1.1: in the client lab.

Configure

npm

A project-level .npmrc — or ~/.npmrc, for every project of a user:

registry=https://proxy.example.com/v1/npm/

In a CI job or a Dockerfile, the environment does the same without a file:

export NPM_CONFIG_REGISTRY=https://proxy.example.com/v1/npm/

To send only one scope through an upstream, name the scope. This is also how Node package managers install JSR packages, which JSR serves from an npm-compatible registry of its own (https://npm.jsr.io, here behind an upstream called npm-jsr):

registry=https://proxy.example.com/v1/npm/
@jsr:registry=https://proxy.example.com/v1/npm-jsr/

Yarn 1 (classic)

Yarn 1 has its own file, .yarnrc (project) or ~/.yarnrc:

registry "https://proxy.example.com/v1/npm/"

Yarn 2 and later

.yarnrc.yml (project) or ~/.yarnrc.yml:

npmRegistryServer: "https://proxy.example.com/v1/npm"

Corepack — which downloads the Yarn (or pnpm) release that package.json names — is a client of the npm registry too, and has its own setting:

export COREPACK_NPM_REGISTRY=https://proxy.example.com/v1/npm

pnpm

pnpm reads .npmrc: the npm configuration above applies as it is.

Bun

bunfig.toml (project) or ~/.bunfig.toml:

[install]
registry = "https://proxy.example.com/v1/npm/"

Authenticate

Only when the proxy has access control switched on. The proxy takes your proxy token as a bearer token — never an npmjs.org token; the proxy holds the upstream’s credentials itself.

npm and pnpm — a line in .npmrc that scopes the token to the registry URL (the trailing slash matters):

//proxy.example.com/v1/npm/:_authToken=<token>

Keep the token out of a project .npmrc that is committed: put this line into ~/.npmrc, which is what npm config set writes:

npm config set //proxy.example.com/v1/npm/:_authToken "<token>"

Yarn 1 reads the token from .npmrc and sends it with every request only when always-auth is set:

//proxy.example.com/v1/npm/:_authToken=<token>
always-auth=true

Yarn 2 and later — in .yarnrc.yml (prefer ~/.yarnrc.yml for the token):

npmAlwaysAuth: true
npmAuthToken: "<token>"

Bun — the registry entry with its token:

[install]
registry = { url = "https://proxy.example.com/v1/npm/", token = "<token>" }

Corepack takes it from the environment:

export COREPACK_NPM_TOKEN="<token>"

With several upstreams (the @jsr scope above), each registry URL needs its own _authToken line.

Trust a private CA

Only when the proxy’s certificate is issued by a CA that is not in the system trust store. Node.js does not use the system store by default, so each client is told where the CA certificate is.

npm and pnpm — in .npmrc:

cafile=/etc/ssl/corp-ca.pem

Yarn 1 — in .yarnrc:

cafile "/etc/ssl/corp-ca.pem"

Yarn 2 and later — in .yarnrc.yml:

httpsCaFilePath: /etc/ssl/corp-ca.pem

Bun — in bunfig.toml, under [install]:

cafile = "/etc/ssl/corp-ca.pem"

npm, Yarn, pnpm and Corepack — Node’s own variable, which adds the CA to the built-in ones for every Node process:

export NODE_EXTRA_CA_CERTS=/etc/ssl/corp-ca.pem

Check that it works

npm ping
npm view left-pad version

npm ping prints the registry it reached (PING https://proxy.example.com/v1/npm/). After an install, the lock file shows where each package came from (below). ptctl selftest checks every upstream at once, and tells a network problem from a rejected token (client CLI).

Good to know

On the proxy

upstreams:
  npm:
    type: npm
    url: https://registry.npmjs.org

Packuments are served live with their tarball URLs rewritten to the proxy (which is why server.publicUrl must be set); tarballs are cached immutably. A private or scoped registry is another upstream of type npm, with its credentials on the proxy. Details: backends: npm.