DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • GitLab Pages Preview
  • Overcoming Challenges in UI/UX Application Modernization
  • How to Format Articles for DZone

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • GitLab Pages Preview
  • Overcoming Challenges in UI/UX Application Modernization
  • How to Format Articles for DZone
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using NPM Private Modules in Your CI Workflow

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!

Manisha Sahasrabudhe user avatar by
Manisha Sahasrabudhe
·
Oct. 03, 17 · Tutorial
Like (1)
Save
Tweet
Share
7.74K Views

Join the DZone community and get the full member experience.

Join For Free

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:

  //registry.npmjs.org/:_authToken=GFYR$E8D-89DG-GH54-HJDR-TYDGOSYT785T  

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:

env: 
  - NPM_TOKEN=GFYR$E8D-89DG-GH54-HJDR-TYDGOSYT785T

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:

NPM_TOKEN=GFYR$E8D-89DG-GH54-HJDR-TYDGOSYT785T

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

env:
  - 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:

ci:
  - 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!

Continuous Integration/Deployment Npm (software) workflow

Published at DZone with permission of Manisha Sahasrabudhe, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • GitLab Pages Preview
  • Overcoming Challenges in UI/UX Application Modernization
  • How to Format Articles for DZone

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: