Daniel Pulitano
Daniel Pulitano

Reputation: 133

Can you configure NO_PROXY in NPM?

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?

Upvotes: 11

Views: 29504

Answers (2)

Jonathan POIRIER
Jonathan POIRIER

Reputation: 101

With npm 5.3.0 / node 8.4.0, the NO_PROXY environment variable works as a charm !

Upvotes: 5

GFoley83
GFoley83

Reputation: 3559

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).

Upvotes: 15

Related Questions