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.
Enable the cache
Section titled “Enable the cache”The cache runs inside the cluster that hosts your Workers, so how you get it depends on your Nx Cloud deployment:
- Dedicated compute cluster: the cache is an Nx Cloud add-on that runs on a dedicated compute cluster. Once the cluster is active, open Settings > Add-ons for your organization. On the Dedicated compute cluster card, find npm read-through cache, click Request add-on, and confirm.
- Single-tenant: the cache is available for hosted single-tenant deployments. Contact the Nx team to add it to your deployment.
Cache address
Section titled “Cache address”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:
| Deployment | Cache address |
|---|---|
| Dedicated compute cluster | http://npm:4873/ |
| Single-tenant | http://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.
Configure the default registry
Section titled “Configure the default registry”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:
registry=<cache-url>Yarn Modern ignores .npmrc and reads the registry from npmRegistryServer in .yarnrc.yml:
npmRegistryServer: '<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.
Route private packages
Section titled “Route private packages”Map each private package scope to the registry that hosts it. The scoped setting takes precedence over the default cache registry:
registry=<cache-url>@<package-scope>:registry=https://<private-registry-host>/npm/You can also write the scoped setting with the npm CLI:
npm config set @<package-scope>:registry https://<private-registry-host>/npm/Configure package publishing
Section titled “Configure package publishing”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.
Configure an agent setup step
Section titled “Configure an agent setup step”Add the registry settings before the dependency installation step in your launch template:
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.
Understand cache behavior
Section titled “Understand cache behavior”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.