Selecting another npm registry via .npmrc
To configure the behavior of npm, a special file called .npmrc
is used. We’ve already briefly touched on this file in Chapter 3, Choosing a Package Manager. This file can be used not only to determine the source of the packages but also to define where to publish to.
A simple modification might look as follows:
.npmrc
; Lines starting with a semicolon or
# with a hash symbol are comments
registry=https://mycustomregistry.example.org
This way, all installations and publish attempts will be performed at https://mycustomregistry.example.org
instead of the official registry located at https://registry.npmjs.org
.
Quite often, this extreme approach is unnecessary or even unwanted. Instead, you might only want to use another registry for a subset of the packages. In the most common case, the subset is already defined by a scope.
Let’s say the @foo
scope that we used in the previous section with the @foo/bar
package...