When using a private npm repository, I need the ability to send some requests through a proxy server and others direct to the server.
Usually, setting the environment variables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY resolve this.
I understand npm does not have a command-line option for no_proxy, but I haven't been able to get npm to respect the NO_PROXY environment variable: After setting the environment variables above, npm install times out when downloading external libraries (which require to be downloaded through the corporate proxy)
My ~/.npmrc file has the following:
registry=http://[internal_npm_registry]
email=[email]
I am running npm version 3.10.10. Has anyone had the same need and resolved it?
The NO_PROXY environment variable specifies URLs that should be excluded from proxying (on servers that should be contacted directly). This should be a comma-separated list of hostnames, domain names, or a mixture of both. Asterisks can be used as wildcards, but other clients may not support that.
Go to command prompt or terminal depending on your machine(tip: hit Win + R and type cmd). In the command prompt type the following command npm config set proxy http://<username><password>@proxy-server-url>:<port> then config set https-proxy http://<username><password>@proxy-server-url>:<port> .
You can locate your proxy settings from your browser's settings panel. Once you have obtained the proxy settings (server URL, port, username and password); you need to configure your npm configurations as follows. username, password, port fields are optional. Once you have set these, your npm install , npm i -g etc.
I had the same problem at work: we have a private Nexus npm repository where we host some custom modules and we needed npm to not use the proxy when requesting these packages.
The only reliable solution I found for Windows was by setting the environment variables you listed and actually removing all proxy values from npm (set proxy
, https-proxy
and https_proxy
all to null
in your .npmrc
file).
So for example, the .npmrc
file in the project root looks like this:
strict-ssl=false
ca=null
registry=http://my-nexus-repo.com/repository/npm-packages/
my-custom-registry-on-nexus:registry=http://my-nexus-repo.com/repository/hosted-npm-packages/
https_proxy=null
https-proxy=null
proxy=null
Sticking with the example above, your no_proxy
environment variable would look something like:
my-nexus-repo.com,localhost
Doing this allowed us to seamlessly install all npm packages (even tricky ones like node-sass
that download tarballs outside of npm).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With