How to exclude certain domains from an npm proxy

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

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

Tags:

Proxy

Npm