Skip to content
jshacks.dev
Packages

Use a scoped registry per scope

Send each npm scope to its own registry with a scope:registry line in .npmrc, so private and public packages install side by side. npm 10.

1 min read
Summarize in AI

A company often has several registries: its own for @acme, GitHub Packages for @labs, and npmjs.org for everything else. Each scope can name its registry in .npmrc.

.npmrcText
@acme:registry=https://registry.acme.example.test/
@labs:registry=https://npm.labs.example.test/
//registry.acme.example.test/:_authToken=${ACME_TOKEN}
Shell
npm config get @acme:registry
npm config get @labs:registry
Text
https://registry.acme.example.test/
https://npm.labs.example.test/

A package named @acme/ui is fetched from the first host, @labs/charts from the second and express from the default registry. Auth lines are matched by host, so only the registries that need a token get one. See the scope documentation.

The scope is part of the package name, so one scope cannot be split across two registries. Names also matter for security: an internal name without a scope may be taken on the public registry by someone else, and npm would fetch theirs.

Scope every internal package, and keep the registry mapping in the project, so CI and laptops resolve the same way.

Taggednpm
Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.