How to Publish NPM Packages to GitLab Package Registry

In this article we are going to cover How to Publish NPM Packages to GitLab Package Registry.

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.

npmrc

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/"
  }
packagejson

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

pipeline 1

Step #4:To check NPM package push to GitLab package registery

Go to project/particular repository > Deploy section > package registry

package regi

Click on @devopshint/npm-package-Registry

package regi 2

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:

GitLab Package Registry

About Priti Adkine

I am Priti Adkine working as Software Engineer and having 1+ years of Experience. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link