Skip to content

Instantly share code, notes, and snippets.

@aulisius
Created June 20, 2023 08:34
Show Gist options
  • Save aulisius/1a6e4961f17039d82275a6941331b021 to your computer and use it in GitHub Desktop.
Save aulisius/1a6e4961f17039d82275a6941331b021 to your computer and use it in GitHub Desktop.
GH Packages Setup

GitHub Packages

GitHub has its own registry for npm packages that is available at https://npm.pkg.github.com/

This guide will explain how to login into it so that you can start installing packages from the registry.

Generating token

Unlike the NPM registry which uses a password login, GitHub registry uses a Personal Access Token (PAT) as the credential.

To create the PAT, you'll have to do the following steps

  • Go to Tokens under Settings
  • Choose option to Generate new token (Classic)
  • Enter your password
  • Select the read:packages scope
  • Set expiration to No expiration
  • Give a name to the token
  • Click on Generate Token
  • Copy the displayed token and store it for the next step

Login into registry

This requires a npm CLI.

npm login --registry https://npm.pkg.github.com/ --scope @newfold-labs

This command will log us in to the GitHub registry and point it to the scope that we need, i.e. @newfold-labs

Enter the requested details (replace password with token generated above) and once you're done, you should see this message.

Logged in as <github-username> to scope @newfold-labs on https://npm.pkg.github.com/.

You can now freely install packages from GitHub registry that are under @newfold-labs.

@circlecube
Copy link

You can also set up a local user-specific .npmrc file to hold this token. Make sure it is not within a repo and is never committed. Once you have a token setup on your github account, add it to your local personal ~/.npmrc file (not in the repo but in your main/Users dir). It would be updated to something like this:

legacy-peer-deps=true
@newfold-labs:registry=https://npm.pkg.github.com/
# Personal Newfold Token
//npm.pkg.github.com/:_authToken=ghp_XXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment