Globally configure NPM with a token registry to a specific scope (@organisation)
Asked Answered
M

1

37

I want to globally setup an NPM registry for a specific scope to be used with a specific token.

I know that I can use :

$ npm login --scope=@organisation

And I can also write a ~/.npmrc with :

//registry.npmjs.org/:_authToken=XXXX

But what I want is a combinaison of the two methods: Using the token at when assigning the registry URL to my scope.

I tried :

npm config set @organisation:registry https://registry.npmjs.org/:_authToken=XXXX

But when running an NPM command (eg npm install @organisation/my-package). I get the following error :

npm ERR! Darwin 15.6.0
npm ERR! argv "/Users/me/.nvm/versions/node/v6.2.2/bin/node" "/Users/me/.nvm/versions/node/v6.2.2/bin/npm" "install" "@organisation/my-package"
npm ERR! node v6.2.2
npm ERR! npm  v3.10.3
npm ERR! code E403
npm ERR! you do not have permission to publish ":_authToken=XXXX". Are you logged in as the correct user? : :_authToken=XXXX

Is there a solution? (I need to use a token and no env variable).

PS: https://github.com/npm/npm/issues/7995#issuecomment-175915766 but it's not working...

Meghan answered 4/8, 2016 at 10:22 Comment(0)
D
85

According to the official documentation you should be able to associate a scope with a registry when logging in. Is this what you want?

Did you try the following?

npm login --registry=https://reg.example.com --scope=@myco

If you dont want to login, but rather want to specify the token explicitly, the following should work:

npm config set @myco:registry https://reg.example.com
npm config set //reg.example.com/:_authToken xxxxxxxx

Note that the registry url must be normalized for this to work, ie it shouldn't include scheme and must end with a slash.

Darmit answered 8/2, 2017 at 13:37 Comment(3)
Having problems doing npm install through token. are the quotes '' supposed to be there, and the sample registry url above looks like it doesn't end with a slashHyperparathyroidism
Just to add: 'npm config set' will just put these two line put this into ~/.npmrcBruiser
What if npm is your registry? You just want a token only for a specific scope?Shawn

© 2022 - 2024 — McMap. All rights reserved.