npm 的服务器在国外, 因为国情,经常访问缓慢,故搭配我的 ss 给 npm 代理加速
先配置 ss
因为 npm 代理是走 http 的通道,而 shadowsocks 提供的是 socks5 通道,故需要将 shadowsocks 的 sock5 通道 转换为 http 通道
有 2 种方法
1. 将 ss 本地端配置成 http(s) 类型 (方便)
若你的 ss 客户端支持把 本地端配置成 http 类型 ,就将其配置成 http(s) 类型即可
2. 安装 kneesocks 包,作用:将 http 包转换为 sock5 类型的包1
2$ npm install kneesocks -g # 下载安装 kneesocks 包
$ DEBUG=proxy kneesocks httpPort sock5Port # 开启 kneesocks 转换
注:
若 node 版本高于 7 时, 需将.npm-global/lib/node_modules/kneesocks/node_modules/socksv5/lib/client.js`修改成 client.js
再配置 npm
1 | $ npm config set proxy http://127.0.0.1:httpPort |