ARTIFACTORY: Configure an NPM Gitlab registry in remote repository
Here, we are going to see how to configure a Gitlab private NPM Registry in the Artifactory remote repository. If you do not already have a GitLab NPM registry, please scroll down to find the steps to prepare Gitlab NPM registry.
Create a Gitlab Remote repository
The steps to mirror the Gitlab private repository in JFrog Artifactory.
Step 1: Create a Deploy token from Gitlab and copy the Username and Access token
Step 2: Create an NPM remote repository in Artifactory with the Gitlab URL
1. Go to Artifactory → Administration → Repositories → Add Repositories → Remote Repositories → NPM
2. Create a repository with <your_npm_reponame> as the Repository Key
3. Update URL field with the Gitlab registry URL in the below format
https://gitlab.com/api/v4/projects/<project_ID>/packages/npm/
5. Create Remote Repository
Here is an example of a remote npm repository with the name “npmlab”
Note: Since it is a private registry, “Test” may show “Target remote URL returned error 404: Not Found”, however you can ignore this error message and move forward.
Step 3: Copy the NPM client configuration snippets from “Set Me Up” and update .npmrc
1. Go to Artifactory → Application → Artifacts → your_npm_reponame → Set Me Up(Top Right Hand Side)
2. Enter password in the respective text box and copy the code snippet for scoped packages under Using basic authentication
3. Replace <SCOPE> with the scope in your registry
4. Add the code snippet to ~/.npmrc file(If Windows, %USERPROFILE%\.npmrc)
Step 4: Install npm package using “npm install @<SCOPE>/package_name”

To Prepare GitLab NPM RegistryCreate a Project in GitLab:
GitLab > Create new project > Create blank project > Select Project deployment target as “Registry”
For more details, please refer to this documentation.
To publish an NPM package, the following is required:
1. Project ID: Click on your project and you can find your Project ID
2. Scope: The value used for the @scope is the root of the project that will host the packages and not the root of the project with the source code of the package itself. The scope should be lowercase.
3. Deploy Token
Create a Deploy Token:- Go to Your Project > Settings > Repository > Deploy Tokens.
- Enter the Name, Username, and select read_package_registry, write_package_registry as Scopes
- Create deploy Token
Create a sample npm package and publish it to GitLab:
2. Add publishConfig with the npm package registry location.
Sample Package.json:
{
"name": "@testjf/helloworld",
"version": "1.0.0",
"description": "To print Hello World.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"Hello"
],
"author": "Your Name",
"license": "ISC",
"publishConfig": {
"@testjf:registry": "https://gitlab.com/api/v4/projects/<project_ID>/packages/npm/"
}
}# Set URL for your scoped packages.
@jftest:registry=https://gitlab.com/api/v4/projects/<project_ID>/packages/npm
# Add token for uploading to the registry. Replace <my-project-id>
//gitlab.com/api/v4/projects/<project_ID>/packages/npm/:_authToken="${NPM_TOKEN}"
Never hardcode GitLab tokens (or any tokens) directly in .npmrc files or any other files that can be committed to a repository.
4. Sample index.js file
function helloWorld() {
console.log('Hello World from this npm package');
}
module.exports = helloWorld;NPM_TOKEN=<my_deloy_token> npm publish