Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude certain domains from an npm proxy

Tags:

We use npm behind a company firewall and thus use proxy and https-proxy settings in the npm configuration. This works fine as long as all npm modules are loaded from an external registry. But as a matter of fact we also have internal modules on an internal github. The access to these modules must not use the proxy of course. My question is: Can I specify a list of domains in the npm configuration, for which the proxy should not be used? Something like the no_proxy environment variable in the unix shell?

like image 262
Gregor Avatar asked Sep 23 '14 07:09

Gregor


People also ask

How do I remove HTTP proxy from npm config?

By running npm config rm proxy you remove proxy from user configuration. This can be easily verified by running: npm config list. If there is proxy or https-proxy setting set in global config you have to use --global in the command to remove it.

What does no_proxy mean?

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.


2 Answers

Assuming your environment looks like this:

  • Build server with internet access only over proxy: your.proxy.host:3128
  • Local Nexus Registry: https://your.local.nexus.registry/nexus/content/groups/npm/

NPM must use local Nexus Registry. Configuration file: .npmrc

registry = https://your.local.nexus.registry/nexus/content/groups/npm/ 

You can tell npm to use a proxy by setting the environment variables

http_proxy=http://your.proxy.host:3128 https_proxy=http://your.proxy.host:3128 

but then npm will also try to reach your (local) Nexus Registry using the proxy.

You need to have one of the latest npm Versions (npm 2.14.7 works fine) and set an additional environment variable to exclude your Nexus Registry from the proxy:

no_proxy=your.local.nexus.registry 
like image 174
adiesner Avatar answered Sep 23 '22 22:09

adiesner


Since NPM 6.4.1, released on 2018-08-22, you can use the noproxy option, even with a custom registry configured.

Example :

  • npm config set registry "http://<my-npm-registry-host>:<registry-port>"
  • npm config set proxy "http://<my-proxy-host>:<proxy-port>"
  • npm config set https-proxy "http://<my-proxy-host>:<proxy-port>"
  • npm config set noproxy "my-proxy-host" (accepts pattern like *.domain)

Check config :

  • npm config list

References :

  • NPM doc for noproxy
  • NPM changelog
  • NPM PR #46
like image 31
Guillaume Husta Avatar answered Sep 22 '22 22:09

Guillaume Husta