NPM config for web access via a proxy
If you are using NPM for to install your JavaScript modules and you are sitting behind a corporate proxy server with a strict firewall then you will likely be having problems. If NPM cannot find its way out to the web you will likely be getting a timeout error like the one below:
1
2
3
4
5
6
7
8
9
10
11
12
13
npm ERR! argv "C:\node.exe" "C:\nodejs\node_modules\npm\bin\npm-cli.js" "install" "package1"
npm ERR! node v4.2.1
npm ERR! npm v2.14.7
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT 185.31.18.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
To resolve this problem you need to tell NPM the address of your web proxy, including the username/password to authenticate, so that it can route outgoing HTTP requests via that proxy. NPM stores its configuration in a config file and can be edited via the console/terminal using “NPM Config” command. Use this command to set set both the HTTP and HTTPS values replacing the username/password and proxy address with your custom values:
1
2
npm config set proxy [http://username:password@yourproxy.yourcompany.com:8080/](http://username:password@yourproxy.yourcompany.com:8080/)
npm config set https-proxy [http://username:password@yourproxy.yourcompany.com:8080/](http://username:password@yourproxy.yourcompany.com:8080/)
To view the current proxy settings, or to check that your change worked, you can run “npm config get” (as opposed to “npm config set”) to read the settings.
1
2
"npm config get proxy"
"npm config get https-proxy"
Alternatively running only “npm config get” will show ALL NPM config settings.
Should you want to remove the npm setting you can do it like this:
1
2
“npm config rm proxy”"
”npm config rm https-proxy”
For more information checkout the NPM documentation here:https://docs.npmjs.com/misc/config