Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 231
Daniel Pulitano Avatar asked Jan 10 '17 16:01

Daniel Pulitano


People also ask

What is No_proxy setting?

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.

How do I change proxy settings in npm?

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

How do I find my proxy settings for npm?

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.


1 Answers

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

like image 164
GFoley83 Avatar answered Sep 24 '22 09:09

GFoley83