Over a million developers have joined DZone.

Using NPM Private Modules in Your CI Workflow

DZone's Guide to

Using NPM Private Modules in Your CI Workflow

Sometimes we need to make use of NPM private modules when running our CI workflows. In this post, we take a look at how to do just that quickly and easily!

· DevOps Zone ·
Free Resource

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

In addition to publicly available packages, npm also allows users to publish and manage packages in a private namespace. If you want your npm install command in the CI workflow to install your private dependencies, there are a couple of setup steps that are required.

Unless you follow these steps, your npm install command will throw an error, such as

  npm ERR! 404 Not found : @manishas/my-private-module  

Step 1: Get Your npm Auth Token

First, you need to find your npm token, which is stored in the .npmrc file in your home directory. The file will contain a line which looks like this:


Copy the value of the token, which is everything after authToken=

Step 2: Add the npm Token to Your Build Environment

Next, you need to set an environment variable $NPM_TOKEN in your CI workflow. Ordinarily, you would just set this in the env section of your YAML, like this:


However, this will expose your npm token to everyone who has access to your shippable.yml, which means everyone who has access to your repository. To avoid disclosing the token in your config, you can use secure variables. To do this, go to your Shippable UI, navigate to the Subscription or Project Settings page, and enter the following in the Encrypt section:


You will get your encrypted string which should be include in shippable.yml:

  - secure: <encrypted string>

This will add the environment variable NPM_TOKEN to the build environment. Please note that if you change your npm password, then you'll need to update your NPM_TOKEN.

Step 3: Add the .npmrc File to Your bBuild Machine

Last, your build machine needs the .npmrc file. The easiest thing to do is to commit it to the folder in your repository from where the npm install command is executed during CI. This will ensure that the file gets copied to the build machine when the repository is cloned.

Alternatively, you can also generate the file dynamically in your CI config, before calling npm install:

  - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
  - npm install

And that's it! You should be all set to pull private npm packages during your CI workflow!

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

nodejs ,npm ,continuous integration ,devops

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}