1

How can I configure node.js and npm to run behind a web proxy?

I tried the following solutions but they didn't work for me.

npm config set proxy http://proxy.company.com:8080

and

npm config set proxy http://username:password@proxy.company.com:8080
Setthase
  • 13,988
  • 2
  • 27
  • 30
mdali
  • 13
  • 1
  • 1
  • 5
  • Possible duplicate of [Using npm behind corporate proxy .pac](http://stackoverflow.com/questions/25660936/using-npm-behind-corporate-proxy-pac) – Blake Yarbrough Oct 27 '15 at 18:22

2 Answers2

5

First open a command console at the location of your npm installation.

Then you can configure your npm to use a proxy using the commands:

npm config set proxy http://{url}:{port}
npm config set https-proxy http://{url}:{port}

Notice the protocol is set to http for both the proxy and https-proxy variables.

If you would like npm to store your credentials for the proxy, you can additionally modify the commands as follows:

npm config set proxy http://{username}:{passphrase}@{url}:{port}
npm config set https-proxy http://{username}:{passphrase}@{url}:{port}

For example:

npm config set proxy http://LanguidSquid:Password1@my.company.com:8080
npm config set https-proxy http://LanguidSquid:Password1@my.company.com:8080

Additional information here: Using npm behind corporate proxy .pac

Community
  • 1
  • 1
Blake Yarbrough
  • 2,286
  • 1
  • 20
  • 36
  • 1
    npm is broke after seting proxy. I am using `node-v6.11.2-linux-x64` version. Exception log: URIError: URI malformed at decodeURIComponent (native) at Url.parse (url.js:269:19) at Object.urlParse [as parse] (url.js:75:5) at Object.validateUrl [as validate] (/app/phoenix/node-v6.11.2-linux-x64/lib/node_modules/npm/node_modules/nopt/lib/nopt.js:164:13) please advise @Blake – Joey Trang Aug 03 '17 at 09:24
4

This worked for me!

  1. npm config set strict-ssl false
  2. npm config set registry https://registry.npmjs.org/
  3. npm config set proxy http://login:pass@host:port
  4. npm config set https-proxy http://login:pass@host:port

NOTE: Remember to add https:// instead of http:// when setting registry

Hope that helps.

Admond Lee
  • 51
  • 5
  • `npm config set strict-ssl false` is doing the trick when behind a proxy PAC, but it is a bit dirty... why NPM can't use the proxy PAC settings ? – fallais Oct 21 '21 at 07:01