Use a new registry
For those developers who live in China, you may have the problem when installing packages with NPM or Yarn, it could take hours to get the installation done or even failed after a long time.
There are several ways to address this problems, the easiest way might be using a custom registry, for example the one provided by Taobao:
1 | npm config set registry http://registry.npm.taobao.org |
This works, however, remember to restore the registry to its original one before publishing packages:
1 | npm config set registry https://registry.npmjs.org |
Keep it intact
If you prefer not to change the default registry, you could use NPM behind a proxy server.
Run the following commands one by one in your favourite terminal:
1 | npm config set strict-ssl false |
Suppose you have a proxy running on localhost and the port is 8118
, then the format is:
1 | npm config set https-proxy http://127.0.0.1:8118 |
Run the following commands to check your proxy settings:
1 | npm config get proxy |
Forward traffic to a SOCKS5 proxy
If you are running a socks5 proxy server rather than an http proxy server, you will have to forward all http traffic to it, because NPM has no native support for socks proxies. I would recommend Privoxy as it does a good job for it.
- Download and install Privoxy.
- Find its
config.txt
file in the directory where it was installed. - Add this line to it, suppose your socks5 proxy is running on port
1080
:
1 | forward-socks5 / 127.0.0.1:1080 . |
- Then you are able to use the HTTP or HTTPS proxy at
127.0.0.1:8118
, as Privoxy listens127.0.0.1
and the port8118
by default.
Disable proxy
1 | npm config rm proxy |