Reputation: 365
I am trying to use npm to install a package from url : http://host:80
I did the following: npm config set strict-ssl false npm config set registry "<>" npm --proxy http://host:port install <> (our proxy does not require authentication)
When I tired to run above install package command it throws npm ERR! code E401 npm ERR! 401 Authorization Required: @latest
When I should I set the username and pwd for registry url.I googled and found that registry url and details are part of .npmrc file.
Currently it has
strict-ssl=false
registry=<>enter code here
Should I add username and password here in this file ? If so can you give me the format or how to add it or where to add it.Thank you.
Upvotes: 9
Views: 61146
Reputation: 622
You can set separate profile(s) for the secondary registry, in your case http://host:80
using npmrc
tool.
First install npmrc
globally on your machine with:
npm i npmrc -g
Make sure installation went fine, by listing all available profiles:
npmrc
It should show your default
profile.
Add a separate profile, so you can customise your registry hostname, with:
npmrc -c work
where work
can be any preferable name for your profile.
Select it with:
npmrc work
Then add your specific hostname with:
npm config set registry http://host:80
Finally add user with credentials and email, using:
npm adduser
It will prompt you for all needed data.
To switch back to default profile (with default npm registry), you can use:
npmrc default
Upvotes: 1
Reputation: 2326
If you want to auth to your NPM registry (like Artifactory)
You can provide the login details as below at runtime
npm login
Alternatively you can paste following in the .npmrc file.
_auth = <USERNAME>:<PASSWORD> (converted to base 64)
email = [email protected]
always-auth = true
If you are getting any SSL issues you can add following to disable SSL
strict-ssl=false
If you want to configure proxy settings
npm config set proxy http://"username:mystrongpassword"@proxy.mycompany.com:PORT
npm config set https-proxy http://"username:mystrongpassword"@proxy.mycompany.com:PORT
Upvotes: 12