Use npm behind a corporate proxy


From what I understand within my several tests using npm behind a proxy.
There is no simple solutions. And as most of the time, what happens behind a proxy doesn't rely on your developer skills, you must find a way to get your updates no matter what these network guys are doing.

Especially if you are on Windows, forget editing any file ! Just use the NPM CLI. It is reliable and persistent.

Basically, if you trust your proxy, you could just use

npm config set proxy http://yourproxy:8080
npm config set https-proxy http://yourproxy:8080

Setting strict-ssl to false and using http registry instead of https could also do the trick if your proxy isn't handling https. But I wouldn't advise that.

It could work flawlessly for a while then break down, like me when for any reason for instance your corporate proxy falls behind a cloud proxy (how useful …). You won't be able to do a thing and would end up with errors like :
cb() never called!

You'll see that this issue is quite generic and pretty hard to debug.
From my part I knew it had nothing to do with what MacOS and other Unix users were encountering and stuck to the proxy / network part.

You know your browser and system has access to the network on both 80 and 443 ports (try to telnet / paping registry.npmjs.org on both port, this shall give you a hint)

Once you are sure your system can indeed reach the registry you'll have to set a local proxy.
By doing so, the requests will first go through the local proxy then follow the corporate flow.

So in 3 steps :
  • Install Fiddler (a free HTTP analysis tool)
  • Set npm proxy to use the local proxy Fiddlers create to intercept requests
    • npm config set proxy http://127.0.0.1:8888
    • npm config set https-proxy http://127.0.0.1:8888
  • Enjoy your npm install <package> working just fine !

There must be a proper way to configure your workstation, npm or even networking/proxy rules to better handle these cases. This one is just a quick and dirty workaround that shall allow you to don't waste much time configuring your environment.


Commentaires

Articles les plus consultés