Skip to content

Instantly share code, notes, and snippets.

@Abrifq
Created November 19, 2023 04:43
Show Gist options
  • Save Abrifq/e2c35011718a77d63b922bb0a3f15dd1 to your computer and use it in GitHub Desktop.
Save Abrifq/e2c35011718a77d63b922bb0a3f15dd1 to your computer and use it in GitHub Desktop.
Manage multiple registries with this NPM hack!
@@github:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=authtoken
//registry.npmjs.org/:_authToken=authtoken

How to manage multiple npm registries by naming them

TL;DR, view the example .npmrc file

Why would you even want to?

I like shiny rocks and big numbers, so I decided to push my NPM work to my github packages. NPM allows you to scope one scope to a registry. Which wasn't what I wanted.

I wanted to push both to the npmjs registry and the github registry, without writing the url every dang time!

So, exploiting some naming schemes, I'm able to present you this: @@! According to the NPM docs on creating an account, you cannot use @ in your usernames. And by design, every username is a scope, referrable by @username. So, I tried putting double at-signs, and woila! I have a name that can't be created on the registry which can be used for shorthands!

Now I have a registry shortcut!

Commands to add yours

# setup registry with fake scope
npm login --auth-type=legacy --registry=https://registry.site --scope=@@registry

#publish a package to both registries
npm publish # to npmjs
npm publish --scope=@@registry # to the private registry!
keywords

npm

naming registries

registry shortcuts

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