import{_ as a}from"./chunks/PageInfo.vue_vue_type_script_setup_true_lang.250b3e56.js";import{_ as p,o,c as e,H as l,k as s,a as t,Q as r}from"./chunks/framework.b7580407.js";import"./chunks/commonjsHelpers.725317a4.js";const _=JSON.parse('{"title":"Installing NPM Packages Behind Proxy","description":"","frontmatter":{},"headers":[],"relativePath":"development/installing-npm-package-behind-proxy.md","filePath":"development/installing-npm-package-behind-proxy.md","lastUpdated":1726415491000}'),c={name:"development/installing-npm-package-behind-proxy.md"},i=s("h1",{id:"installing-npm-packages-behind-proxy",tabindex:"-1"},[t("Installing NPM Packages Behind Proxy "),s("a",{class:"header-anchor",href:"#installing-npm-packages-behind-proxy","aria-label":'Permalink to "Installing NPM Packages Behind Proxy"'},"")],-1),y=r(`
On a recent assignment, I needed to install npm behind a corporate proxy. I had already set the environment variables HTTP_PROXY and HTTPS_PROXY. Other command line utilities, like ruby gems, recognized these environment variables. Npm did not.
After some googling, I found the following way to configure the proxy for npm.
# npm
npm config set proxy <http://127.0.0.1:7890>
npm config set https-proxy <http://127.0.0.1:7890>
# yarn
yarn config set proxy <http://127.0.0.1:7890>
yarn config set https-proxy <http://127.0.0.1:7890># npm
npm config set proxy <http://127.0.0.1:7890>
npm config set https-proxy <http://127.0.0.1:7890>
# yarn
yarn config set proxy <http://127.0.0.1:7890>
yarn config set https-proxy <http://127.0.0.1:7890>If you need to specify credentials, they can be passed in the url using the following syntax.
[<http://user_name:password@proxy.company.com:8080>](<http://user_name:password@proxy.company.com:8080/>)[<http://user_name:password@proxy.company.com:8080>](<http://user_name:password@proxy.company.com:8080/>)Further exploration of the npm config documentation showed that the npm config set command sets the proxy configuration in your .npmrc file. You can also set the proxy configuration as a command line argument or environment variable.
Configuration parameters can be specified using -- when executing npm. So the proxy could also be specified as follows.
npm --https-proxy=http://proxy.company.com:8080 -g install karmanpm --https-proxy=http://proxy.company.com:8080 -g install karmaTo pass configurattion parameters to npm as environment variables, they must be prefixed with npm_config_. The proxy configuration could be set with environment variables as follows.
export npm_config_proxy <http://proxy.company.com:8080>
export npm_config_https_proxy <http://proxy.company.com:8080>export npm_config_proxy <http://proxy.company.com:8080>
export npm_config_https_proxy <http://proxy.company.com:8080>