From 25805d6718cbf601bdc90b4bfcf858fb65c64301 Mon Sep 17 00:00:00 2001 From: "@andatoshiki" Date: Tue, 23 Apr 2024 20:58:48 -0700 Subject: [PATCH] doc(npm): add documentation for installing npm packages behind the proxy with its affiliated sidebar hyperlink entry components accordingly --- docs/.vitepress/config/sidebar.ts | 4 +++ .../installing-npm-package-behind-proxy.md | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 docs/development/installing-npm-package-behind-proxy.md diff --git a/docs/.vitepress/config/sidebar.ts b/docs/.vitepress/config/sidebar.ts index 760c2e32..72aa705e 100644 --- a/docs/.vitepress/config/sidebar.ts +++ b/docs/.vitepress/config/sidebar.ts @@ -18,6 +18,10 @@ export const sidebar: DefaultTheme.Config['sidebar'] = { text: 'Git push results in "Authentication Failed"', link: '/development/git-push-authentication-failed', }, + { + text: 'Installing NPM Packages Behind Proxy', + link: '/development/installing-npm-package-behind-proxy' + } ], }, { diff --git a/docs/development/installing-npm-package-behind-proxy.md b/docs/development/installing-npm-package-behind-proxy.md new file mode 100644 index 00000000..34e21308 --- /dev/null +++ b/docs/development/installing-npm-package-behind-proxy.md @@ -0,0 +1,36 @@ +# Installing NPM Packages Behind Proxy + +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. + +```bash +# npm +npm config set proxy +npm config set https-proxy + +# yarn +yarn config set proxy +yarn config set https-proxy +``` + +If you need to specify credentials, they can be passed in the url using the following syntax. + +``` +[]() +``` + +Further exploration of the [npm config documentation](https://npmjs.org/doc/config.html) 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. + +```bash +npm --https-proxy=http://proxy.company.com:8080 -g install karma +``` + +To 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. + +```bash +export npm_config_proxy +export npm_config_https_proxy +``` \ No newline at end of file