Skip to navigation

Npm Repo Configuration

Our projects use the .npmrc file to direct npm to use our private npm repository (cla_npm). The configuration we use requires and environment variable called NPM_TOKEN to be set in order to connect to the repository.

Template .npmrc file

If your repository contains the .npmrc file configured to consume packages from CLADevOps NPM registry it will look similar to:

registry=https://pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/registry/
always-auth=true
; begin auth token
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/registry/:username=CLADevOps
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/registry/:_password=${NPM_TOKEN}
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/registry/:email=npm@claconnect.com
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/:username=CLADevOps
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/:_password=${NPM_TOKEN}
//pkgs.dev.azure.com/CLADevOps/Development/_packaging/cla_npm/npm/:email=npm@claconnect.com
; end auth token

The NPM_TOKEN environment variable must be set to the Base64 Encoded version of your Azure DevOps Personal Access Token.

Azure DevOps Personal Access Token (PAT)

Navigate to Azure DevOps Personal Access Tokens page.

Click on ”+ New Token”, provide an informative Name for the PAT, create a new PAT with Packaging/Read & Write under Scopes. Securely copy and paste a new Personal Access Token to encode into Base64 in the next step.

Base64 encoding for Azure DevOps Personal Access Token

To securely generate a Base64 version of the Azure DevOps Personal Access Token, use the following script in your terminal:

node -e "require('readline') .createInterface({input:process.stdin,output:process.stdout,historySize:0}) .question('PAT> ',p => { b64=Buffer.from(p.trim()).toString('base64');console.log(b64);process.exit(); })"

Run the command and paste your new PAT.

Alternatively, on your Linux Dev VM this one-liner will work:

echo -n 'YOUR_RAW_TOKEN_HERE' | base64

NPM_TOKEN Environment Variable

In Windows you can create a new NPM_TOKEN Environment Variable using System settings for your local account.

Another option in Windows you can temporarily create a new environment variable by running this pwsh command:

$env:NPM_TOKEN="YOUR_BASE64_TOKEN_HERE"

In linux you can temporarily create a new NPM_TOKEN Environment Variable using this bash command:

export NPM_TOKEN='YOUR_BASE64_TOKEN_HERE'

Or directly from the RAW token you can do this on Linux:

export NPM_TOKEN="$(echo -n 'YOUR_RAW_KEY_HERE' | base64 -w 0)"

If you want to persist the variable across terminal sessions in Linux, you can append the export command to your .bashrc like this:

echo "export NPM_TOKEN=\"$(echo -n "YOUR_RAW_KEY_HERE" | base64 -w 0)\"" >> ~/.bashrc

After running that, reload your shell with source ~/.bashrc to apply the change. These commands are temporary unless otherwise noted.

Test your settings by clearing npm cache (if needed) npm cache clean --force and running npm install from this git repository.