In this article we are going to cover How to Publish NPM Packages to GitLab Package Registry.
Table of Contents
What is Package Registry in GitLab ?
GitLab Package Registry is a feature within GitLab that allows you to store and manage various types of software packages and artifacts. It serves as a centralized location for storing, versioning, and distributing these packages, making it easier for development teams to collaborate and share code across projects.
NPM packages in GitLab Package Registry,” you are likely referring to the ability to store and manage Node.js packages in the GitLab Package Registry. NPM (Node Package Manager) is a popular package manager for Node.js projects, and GitLab allows you to host and manage NPM packages in your GitLab repositories.
How to Publish NPM Packages to GitLab Package Registry ?
Step #1:Create .npmrc file in your repository and add below configuration in your .npmrc file
Create .npmrc file in your repository and add below configuration in your .npmrc file
@scope:registry=https://your_domain_name/api/v4/projects/your_project_id/packages/npm/
//your_domain_name/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}
Replace the @scope
in your NPM package configuration with the root level group of the project you are publishing to and also replace your_domain_name with your domain name ex: gitlab.com, while keeping ${CI_PROJECT_ID}
and ${CI_JOB_TOKEN}
intact as predefined variables.

Step #2:add publishing details to your NPM package.json configuration file
add publishing details to your NPM package.json configuration file
"npmconfigset":{
"@devopshint:registry": "https://gitlab.com/api/v4/projects/CI_PROJECT_ID/packages/npm/"
}

Step #3:Create .gitlab-ci.yml file publish NPM Packages to GitLab Package Registry
Create .gitlab-ci.yml file publish NPM Packages to GitLab Package Registry
image: node:latest
deploy:
stage: deploy
script:
- npm publish
Monitor the Pipeline: Go to your GitLab repository’s build section to

Step #4:To check NPM package push to GitLab package registery
Go to project/particular repository > Deploy section > package registry

Click on @devopshint/npm-package-Registry

Conclusion:
In this article we have covered How to Publish NPM Packages to GitLab Package Registry
Related Articles:
How to Push Maven Packages to GitLab Package Registry ?
Reference: