Tuesday, October 20, 2015

Run NPM behind a proxy


NPM does not obey the proxy configuration set in $http_proxy and $https_proxy as curl and other common tools. It is instead necessary to define NPM-specific settings as follows.
 
npm config set strict-ssl false
npm config set registry "http://registry.npmjs.org/"

# Adjust username, password and proxy endpoint as needed
npm set proxy $http_proxy
# Also for HTTPS: pay attention to protocol 
npm set https-proxy https://<yourproxy>

These last two commands simply write the specified values to their ultimate location: ~/.npmrc

If you need to specify credentials and/or a port, use:

username:password@yourproxy:port, e.g.
proxyuser:pwd123@proxy.mydomain.com:3128