Skip to main content
Version: 1.0.0

NPM Private Registry

This guide covers two types of NPM Private Registries:

  1. NPM Private Registry looks like https://npmjs.com/my-package.

  2. GitHub NPM Registry looks like https://npm.pkg.github.com/my-package.

info

Note: This guide does not cover how to publish packages to the NPM registry. This guide covers how to import and use packages published to NPM Private Registry or GitHub NPM Registry using npm.

1. Create an Private Access Token

For packages on npm.js

To access private packages on the NPM Private Registry, you'll first need to create an authentication token.

npm token create --read-only

See NPM's docs here for detailed instructions.

For packages on npm.pkg.github.com

Generate a Personal Access Token (PAT) with the read:packages scope. You can find this by navigating to Settings -> Applications -> Personal Access Token.

2. Add the token to Zeet

Once you have created your token, add it as an Environment Variable to your Project, which you can find in the General tab in your Project settings.

3. Configure your repo to use the Private NPM registry

Now that you have the right access to your registry, the next step is to configure your repo to use the private NPM registry. You can look at this GitHub repo for reference to see what the configuration will look like.

For packages on npm.js

Now, we create a configuration file for npm in the root directory called .npmrc

For packages on npmjs.com, you need to specify the authentication method for the private NPM registry. ${NPM_TOKEN} will be loaded from the environment variable set in Step 2 at build time; so you don't need to commit any secrets along with your source code!

npm config set registry http://my-private-registry.com:4873
echo "//my-private-registry.com:4873/:_authToken=${NPM_TOKEN}" >> ~/.npmrc

Note that you have to replace my-private-registry.com:4873 with the URL of your private registry.

For packages on npm.pkg.github.com

Add the GitHub Package Registry as an additionally registry in your .npmrc file along with your GitHub PAT.

echo "registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken={GITHUB_TOKEN}" >> ~/.npmrc

4. Install package

Now that everything is configured, you can go ahead and install a package using npm or yarn like this:

For packages on npmjs.com

npm install my-private-registry

or

yarn add my-private-registry

For packages on npm.pkg.github.com

npm install @owner/my-private-repo

or

yarn add @owner/my-private-repo

5. Commit and deploy!

Once you have added your dependencies to package.json and the auth config in .npmrc, commit and push your code to GitHub. Zeet should automatically rebuild and redeploy your Project and inject the Environment variable you set to download your private NPM dependencies!