Everything you need to know how to setup your npm CLI to publish to different registries
If you interact with npm
, you're always interacting with the default registry that is available under https://registry.npmjs.org
. However, there might be instances where you need to instruct npm to use a different registry, especially if you’re using private packages. This could be on a global level, a per-project basis, or even for a single command. Here's a comprehensive guide on how to manage this:
By default, npm uses the public registry. You can change this by running the following commands with your package manager:
npm config set "@namespace:registry" https://npm.acme.com
Alternatively, you might also need to run the following command to set the authentication token:
npm config set "//npm.acme.com/:_authToken" TOKEN
Replace TOKEN
with your license key or authentication token you got
For project-specific registry configuration, you can use a .npmrc
file in the root of your project. Include the line:
@namespace:registry=https://npm.acme.com/
//npm.acme.com/:_authToken=TOKEN
Replace TOKEN
with your licence key or authentication token you got
You can also instruct npm to use a different registry for a single command. To do this, you can provide the --registry
argument. For example:
npm install @namespace/package --registry https://npm.acme.com
However, this option could lead to issues since no authentication token can be provided.
This will instruct npm to fetch the specific package from the specified registry instead of the default one.
These options will allow you to instruct npm
to fetch a specific package from your provided registry instead of the default one. This will also work with any other major package manager such as pnpm
or yarn
as well.
This guide should provide you with all the necessary steps to configure your npm registry settings at different levels. Remember to set the correct URL, namespace, and token to interact with preferred npm package registry.