Node及NPM的一些常规配置

2022-03-04  本文已影响0人  桃花谷主V

1. 查看npm安装源

npm config get registry
// https://registry.npm.taobao.org 显示这样就表示当前安装源是taobao镜像

2. 设置更改npm安装源

  // 将当前的npm安装源改为taobao镜像
  npm config set registry https://registry.npm.taobao.org

3. 使用nrm切换安装源

由于各个地区不同的网络环境,以及镜像同步不全量的问题,在使用淘宝源时仍有可能遇到一次错误,使用 nrm 可以迅速在各个安装源之间进行切换,而且它还带有测速功能,这能让我们很方便地挑选出最适合自己使用的安装源。

npm install -g nrm
nrm ls

/*
  npm -----  https://registry.npmjs.org/
  cnpm ----  http://r.cnpmjs.org/
  taobao --  https://registry.npm.taobao.org/
  nj ------  https://registry.nodejitsu.com/
  rednpm -- http://registry.mirror.cqupt.edu.cn
  skimdb -- https://skimdb.npmjs.com/registry
*/
nrm use cnpm
//  Registry has been set to: https://r.cnpmjs.org/
nrm test
/*
npm ------ 755ms
yarn ----- 1109ms
tencent -- 227ms
cnpm ----- 1141ms
taobao --- 236ms
npmMirror - 1232ms
*/

4. 使用nvm管理node版本

nvm 是 node 的版本管理工具。如果你使用的是 Linux/OS X 一类的操作系统的话,可能系统本身会自带 node ,但是系统自带的 node 版本往往会比较旧,在使用过程中可能会出现各种各样的问题。而手动在系统中安装两个以上版本的 node 是非常复杂和痛苦的。这种情况下就需要使用到 nvm。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
// 或者
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
nvm install node
nvm ls
nvm use <node版本名称>
上一篇 下一篇

猜你喜欢

热点阅读