Read about a proxy variable in a .npmrc
file but it does not work. Trying to avoid manually downloading all require packages and installing.
To setup the http proxy have the -g flag set:
sudo npm config set proxy http://proxy_host:port -g
For https proxy, again make sure the -g flag is set:
sudo npm config set https-proxy http://proxy_host:port -g
I solved this problem this way:
I run this command:
npm config set strict-ssl false
Then set npm to run with http, instead of https:
npm config set registry "http://registry.npmjs.org/"
Then I install packages using this syntax:
npm --proxy http://username:password@cacheaddress.com.br:80 install packagename
Skip the username:password
part if proxy doesn't require you to authenticate
EDIT: A friend of mine just pointed out that you may get NPM to work behind a proxy by setting BOTH HTTP_PROXY and HTTPS_PROXY environment variables, then issuing normally the command npm install express (for example)
EDIT2: As @BStruthers commented, keep in mind that passwords containing "@" wont be parsed correctly, if contains @ put the entire password in quotes
when I give without http/http prefix in the proxy settings npm failed even when the proxy host and port were right values. It worked only after adding the protocol prefix.
Here are the steps that I've followed (Windows):
C:\Users\<WIN_USERNAME>\.npmrc
Export the certificate to your file system from the following address:https://registry.npmjs.org
Navigate to the exported certificate location and issue the following command:
npm config set cafile npm_certificate.cer
Add the following changes to the file:
registry=https://registry.npmjs.org/
strict-ssl=false
https-proxy=http://[proxy_user]:[proxy_password]@[proxy_ip]:[proxy_port]/
cafile=npm_certificate.cer
Now you should be ready to go!
Have you tried command-line options instead of the .npmrc
file?
I think something like npm --proxy http://proxy-server:8080/ install {package-name}
worked for me.
I've also seen the following:
npm config set proxy http://proxy-server:8080/
$ npm config set proxy http://login:pass@host:port
$ npm config set https-proxy http://login:pass@host:port