npm Proxy for Installing Dependencies
on , tagged translations, npm, dependencies, tooling (share this post, e.g., on Mastodon or on Bluesky)
Even though I was already using the Taobao npm mirror, some packages still download from overseas addresses—for example, PhantomJS’s download URL is something like https://bitbucket/xxxx—so without a proxy it still gets stuck.
We can use bitinn/kneesocks to support npm socket proxies; as I understand it, its role is to generate a local HTTP proxy.
Install:
$ npm install kneesocks --production -gCreate a local proxy:
$ kneesocks PORT1 PORT2To explain: PORT1 is an unused new port for kneesocks to listen on, and PORT2 is an existing local proxy—for example, the local port of the Shadowsocks (ss) we already have installed.
For example: kneesocks 1082 1080, where 1080 is the local ss port.
Configure the npm proxy:
$ npm config set proxy http://127.0.0.1:1082
$ npm config set https-proxy http://127.0.0.1:1082[Translator’s note: The original used http instead of proxy.]
Note: Use the kneesocks port.
Then you can run npm install normally.
If you later want to remove the proxy:
$ npm config delete proxy
$ npm config delete https-proxyTo debug the proxy, use the following command:
$ DEBUG=proxy kneesocks PORT1 PORT2(This post is a machine-made, human-reviewed, and authorized translation of overtrue.me/npm-proxy/.)