Skip to content
Nx Cloud CI is in private beta 10.6× faster average CI time with 79% less compute. Join the beta
Back to Knowledge Base

npm read-through cache

The npm read-through cache (also called the npm proxy cache) puts a package registry proxy close to your Workers. The first time a package is requested, it is fetched from the public npm registry and stored in the cache. Repeated installs of the same package are then served from the cache instead of the upstream registry, cutting install time and external network usage.

It also protects your organization from npm registry outages.

The cache runs inside the cluster that hosts your Workers, so how you get it depends on your Nx Cloud deployment:

Each deployment exposes the cache at a fixed address inside the cluster. Use the address for your deployment wherever <cache-url> appears on this page:

DeploymentCache address
Dedicated compute clusterhttp://npm:4873/
Single-tenanthttp://cache.npm.svc.cluster.local:4873/

Both addresses resolve only inside the cluster, so use them from Workers, not from a local machine.

  • Public npm packages only. The cache proxies the public npm registry.
  • Private and scoped packages that require authentication are not cached. Send them directly to your private registry, as described in route private packages.
  • Do not publish packages to the cache. See configure package publishing.

Point your package manager at the cache before it installs dependencies. Put the file at the workspace root or in the Worker home directory:

npm, pnpm, and Yarn Classic read the registry from .npmrc:

.npmrc
registry=<cache-url>

If an existing project-level file sets the registry, update that file. A user-level setting does not override a project-level setting.

Map each private package scope to the registry that hosts it. The scoped setting takes precedence over the default cache registry:

.npmrc
registry=<cache-url>
@<package-scope>:registry=https://<private-registry-host>/npm/

You can also write the scoped setting with the npm CLI:

Terminal window
npm config set @<package-scope>:registry https://<private-registry-host>/npm/

Set a publishing registry for each package that your workspace publishes. The publishConfig field in package.json keeps publish requests away from the cache:

{
"publishConfig": {
"registry": "https://<publishing-registry-host>/npm/"
}
}

You can also pass npm publish --registry <url>. A scoped registry in .npmrc also applies when you publish a package from that scope.

Add the registry settings before the dependency installation step in your launch template:

.nx/pipelines/ci.yaml
launch-templates:
linux-medium:
init-steps:
- name: Configure the npm read-through cache
script: |
npm config set --location=user registry <cache-url>
npm config set --location=user @<package-scope>:registry https://<private-registry-host>/npm/

Use a committed project-level configuration instead when the workspace already defines its registry in .npmrc or an equivalent file.

The cache uses multiple replicas for reliability and local network access. A cold replica still fetches a package from the upstream registry, so the first request in an availability zone can take longer than later requests.

For package manager details, see the npm .npmrc reference, pnpm settings, Yarn Classic configuration, and Yarn Modern configuration.

Last updated: