Store Node.js packages in Artifact Registry

This quickstart shows you how to set up a private Artifact Registry Node.jspackage repository and upload a package to it.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Artifact Registry API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  6. Install the Google Cloud CLI.

    Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.
  7. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  8. Toinitialize the gcloud CLI, run the following command:

    gcloudinit
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  10. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  11. Verify that billing is enabled for your Google Cloud project.

  12. Enable the Artifact Registry API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  13. Install the Google Cloud CLI.

    Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.
  14. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  15. Toinitialize the gcloud CLI, run the following command:

    gcloudinit
  16. Install PowerShell, if you want to connect to a Node.js package repository from Windows.

Required roles

To get the permissions that you need to create and manage Artifact Registry Node.js package repositories, ask your administrator to grant you theArtifact Registry Administrator (roles/artifactregistry.admin) IAM role on your project. For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Launch Cloud Shell

In this quickstart, you will useCloud Shell,which is a shell environment for managing resources hosted onGoogle Cloud.

Cloud Shell comes preinstalled with theGoogle Cloud CLI. The gcloud CLIprovides the primary command-line interface for Google Cloud.

Launch Cloud Shell:

  1. Go to Google Cloud console.

    Google Cloud console

  2. On the Google Cloud console toolbar, clickActivate Cloud Shell:

A Cloud Shell session opens inside a frame lower on the console.You use this shell to rungcloud commands.

Create a Node.js package repository

Create the repository for your Node.js artifacts.

  1. Create the repository.

    Console

    1. Open theRepositories page in the Google Cloud console.

      Open the Repositories page

    2. ClickCreate Repository.

    3. Specifyquickstart-nodejs-repo as the repository name.

    4. Choosenpm as the format andStandard as the mode.

    5. UnderLocation Type, selectRegion and then choose the locationus-central1.

    6. ClickCreate.

    The repository is added to the repository list

    gcloud

    1. Run the following command to create a new Node.js package repository namedquickstart-nodejs-repo in the locationus-central1 with thedescription "Node.js repository".

      gcloudartifactsrepositoriescreatequickstart-nodejs-repo--repository-format=npm\--location=us-central1--description="Node.js package repository"
    2. Run the following command to verify that your repository was created.

      gcloudartifactsrepositorieslist

    For more information about Artifact Registry commands, run thecommandgcloud artifacts.

  2. To simplifygcloud commands, set the default repository toquickstart-nodejs-repo and the default location tous-central1.After the values are set, you don't need to specify them ingcloudcommands that require a repository or a location.

    To set the repository, run the command:

    gcloudconfigsetartifacts/repositoryquickstart-nodejs-repo

    To set the location, run the command:

    gcloudconfigsetartifacts/locationus-central1

    For more information about these commands, see thegcloud config set documentation.

Configure npm

To upload and download packages, you must configure your npm projects withsettings to authenticate with the repository you created. For this quickstart,you'll upload a package and then install it in a second package as adependency.

  1. Download theemoji-regex package, a package thatprovides a regular expression to match all emoji symbols and sequences.

    npmpackemoji-regex

    The command downloads an archive of the package.

  2. Extract the archive into anemoji-regex directory. The following command isfor an archive ofemoji-regex version 10.1.0:

    mkdiremoji-regex &&tarxvfemoji-regex-10.1.0.tgz-Cemoji-regex--strip-components1
  3. Create a second npm package that you'll use to install theemoji-regexpackage from Artifact Registry. For this package, use thenpm initcommand to create a basic package.

    mkdirnpm-package2cdnpm-package2npminit-y

    When prompted, accept default values.

  4. Configure both theemoji-regex andnpm-package2 projects to authenticatewith the Artifact Registry repository that you created.

    1. Run the following command. The command returns configuration settingsto add to your npm configuration file.

      gcloudartifactsprint-settingsnpm--scope=@quickstart

      Thequickstartscope is associated with your repository. When you include the scope incommands to publish or install packages, npm uses your repository. Whenyou publish or install packages without a scope, your configured defaultrepository is used. For more information, see the Node.jsoverview.

      The output of thegcloud command looks like the following example.PROJECT is your Google Cloud project ID.

      @quickstart:registry=https://us-central1-npm.pkg.dev/PROJECT/quickstart-nodejs-repo///us-central1-npm.pkg.dev/PROJECT/quickstart-nodejs-repo/:always-auth=true
    2. Add the configuration settings from the previous step to the project.npmrc file in each npm project. The file in the same directoryas thepackage.json file.

      To learn more about the.npmrc file, see the Node.jsoverview.

      Each Artifact Registry Node.js package repository is associated with an npmregistry endpointhttps://LOCATION-npm.pkg.dev/PROJECT/REPOSITORY. If you createanother Artifact Registry Node.js package repository, npm interacts with it as aseparate registry with its own scope.

  5. Editpackage.json in both theemoji-regex andnpm-package2 projects.

    1. Ensure that the value forname includes thequickstart scope.

      • Foremoji-regex:
      "name":"@quickstart/emoji-regex"
      • Fornpm-package2:
      "name":"@quickstart/npm-package2"
    2. Underscripts, add a script forgoogle-artifactregistry-auth, a client librarythat updates credentials for Artifact Registry repositories.

      "scripts":{"artifactregistry-login":"npx google-artifactregistry-auth --repo-config=./.npmrc --credential-config=./.npmrc"}

Upload a package to the repository

  1. Refresh the access token for connecting to the repository.

    npmrunartifactregistry-login
  2. Add your package to the repository. You can use annpm oryarn command.

    npmpublish
    yarnpublish

View the package in the repository

To verify that your package was added to the repository:

Console

  1. Open theRepositories page in the Google Cloud console.

    Open the Repositories page

  2. In the repository list, click thequickstart-nodejs-repo repository.

    ThePackages page lists the packages in the repository.

  3. Click a package to view package versions.

gcloud

To list the images in the defaultquickstart-nodejs-repo repository, run the following command:

gcloudartifactspackageslist

To view versions for a package, run the following command:

gcloudartifactsversionslist--package=PACKAGE

WherePACKAGE is the package ID.

Installing packages

Install theemoji-regex package from your Artifact Registry repositoryinnpm-package2.

In thenpm-package2 directory, run thenpm install oryarn add command:

npminstall@quickstart/emoji-regex
yarnadd@quickstart/emoji-regex

The command installs theemoji-regex package in thenpm-package2 project.It also updatespackage.json to setemoji-regex as a dependency.

"dependencies":{"@quickstart/emoji-regex":"^10.1.0"}

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Before you remove a repository, ensure that any packages that you want to keepare available in another location.

To delete the repository:

Console

  1. Open theRepositories page in the Google Cloud console.

    Open the Repositories page

  2. In the repository list, select thequickstart-nodejs-repo repository.

  3. ClickDelete.

gcloud

  1. To delete thequickstart-nodejs-repo repository, run the followingcommand:

    gcloudartifactsrepositoriesdeletequickstart-nodejs-repo
  2. If you want to remove the default repository and location settings thatyou configured for the activegcloud configuration, run the followingcommands:

    gcloudconfigunsetartifacts/repositorygcloudconfigunsetartifacts/location

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.