DEV Community

RajeshKumarYadav.com
RajeshKumarYadav.com

Posted on • Updated on

Node.js : Scopes and repositories

Set the repository for the scope "myscope"

npm config set @myscope:registry http://registry.corporation.com
Enter fullscreen mode Exit fullscreen mode

Login at a repository and associate it with the scope "myscope"

npm adduser --registry=http://registry.corporation.com --scope=@myscope
Enter fullscreen mode Exit fullscreen mode

Install a package "mylib" from the scope "myscope"

npm install @myscope/mylib
Enter fullscreen mode Exit fullscreen mode

All together will be -

# Set the repository for the scope "myscope"
npm config set @myscope:registry http://registry.corporation.com
# Login at a repository and associate it with the scope "myscope"
npm adduser --registry=http://registry.corporation.com --scope=@myscope
# Install a package "mylib" from the scope "myscope"
npm install @myscope/mylib
Enter fullscreen mode Exit fullscreen mode

If the name of your own package starts with @myscope and the scope "myscope" is associated with a different repository, npm publish will upload your package to that repository instead.

You can also persist these settings in a .npmrc file:

@myscope:registry=http://registry.corporation.com
//registry.corporation.com/:_authToken=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxx
Enter fullscreen mode Exit fullscreen mode

This is useful when automating the build on a CI server

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.

Top comments (0)