Installing Internal packages
To install internal/private packages, you will need to setup Azure Artifact Credentials. These credentials ensure that only authorized users can use these packages, which helps teams work together more effectively. By having the right access, engineers can easily integrate these private packages into their development processes.
Setting Up Azure Artifacts Credentials
Step 1 - Creating .npmrc file
- Create a
.npmrc
file and save it based on the type of package installation
Location of .npmrc File
- For Global package installation:
.npmrc
should be in root of your system's home directory.
/home/your-username/
├── .npmrc <-- Global .npmrc configuration here
├── other-files-and-directories
- For Project-specific package installation:
.npmrc
should be in the project, same directory as thepackage.json.
file.
project/
├── src
├── .npmrc <-- Project-specific .npmrc configuration here
├── package.json
└── other-files
Summary:
For global packages (e.g., @hubtel/frontend-cli-tool): Save .npmrc in your home directory.
For project-specific packages (e.g., @hubtel/face-verification, @hubtel/event-publisher, etc): Save .npmrc in the project directory with package.json.
Next, paste in the following snippet in the .npmrc file:
; begin auth token
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/registry/:username=hubtel
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/registry/:email=npm requires email to be set but doesn't use the value
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/:username=hubtel
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/hubtel/_packaging/hubtel/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
Step 2 - Creating a personal access token
Next, you have to generate a Personal Access Token
Click on New Token, this should open up a modal.
Define a name for the personal access token. Under Scopes, scroll to Packaging and tick the Read checkbox (the read checkbox under the Packaging section).
Click Create to generate the token, and make sure to copy it, as you won't be able to see it again.
Step 3 - Base64 encode the personal access token from Step 2.
- From a command/shell prompt run:
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(); })"
- Paste your personal access token value and press Enter/Return
- Copy the Base64 encoded value
Step 4
Replace both [BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
values in your .npmrc
file with the Base64 encoded value from Step 3.
You can now install internal npm packages from Hubtel's private registry, ensuring secure access and streamlining your development process.
CHAT SAMMIAT