Search code examples
node.jsnpmsinopianpm-publish

Working with multiple npm registries and user accounts


For all my own stuff I use the public npm registry however one of the clients I am working with at the moment has just installed sinopia and wants to use that for private modules hosted on site.

This is fine, however as I use my laptop in various places I don't really want to tie myself permanently to this registry, so we have set each repo we use here to use a custom registry by default:

  "publishConfig": {
    "scope": "@somecompany",
    "registry": "http://sinopia-box:4873/"
  }

Which will tie the repo I am working on to that registry which is great but I need to authenticate myself with it so I need to setup a user on there, and all subsequent publishes for this repo will need to use this created user account, however I only want to use that when I am using that repository.

So is there a way to be able to keep the normal npm registry as default with my npm user account (which is already saved locally), but somehow just register the user account for this registry so when it publishes to it via npm publish with that custom publishConfig it just knows about the registry and automatically uses the right user account.

As I don't want to be in a position where every morning I have to come in and set registry to this one and use a different account, then go home and reset it to the public npm registry, I just want to let npm know of the user for that registry then forget about it, so is there anyway to have my cake and eat it here?


Solution

  • Turns out all you need to do is:

    npm login --registry=http://myreg.mycompany.com:8080 --scope=@myco

    That tells npm the login you want to use for that registry, so that way you can add as many users for different registries as you need.

    (You dont need the scope but as most companies will use scopes its worth noting)