Node.js 生态

npm、yarn、pnpm、bun、nvm 的代理配置。

npm

bash
npm config set proxy http://127.0.0.1:7898
npm config set https-proxy http://127.0.0.1:7898
# 取消
npm config delete proxy && npm config delete https-proxy

pnpm

bash
pnpm config set proxy http://127.0.0.1:7898
pnpm config set https-proxy http://127.0.0.1:7898

yarn

bash
# Yarn 1
yarn config set proxy http://127.0.0.1:7898
yarn config set https-proxy http://127.0.0.1:7898
# Yarn 2+(Berry)
yarn config set httpProxy http://127.0.0.1:7898
yarn config set httpsProxy http://127.0.0.1:7898

bun

bun 读取 HTTPS_PROXY / HTTP_PROXY 环境变量,设置终端变量即可。

nvm / fnm(下载 Node 本体)

nvm 使用 curl / wget 下载 Node,读取环境变量:

bash
eval "$(cnb env)"   # 或手动 export https_proxy
nvm install --lts

第三方镜像与官方源

如果之前配置过第三方 npm 镜像(registry),可以保留,也可以改回官方源 https://registry.npmjs.org/ 走加速。两者同时使用不会冲突,但官方源包更新最及时。