首页 > 技术文章 > NPM镜像管理

itzhangbao 2020-11-06 18:52 原文

此文列出常见npm命令,大家共勉。

1.查看npm源地址

npm config list

结果:

metrics-registry = "http://registry.npm.taobao.org/"

2.修改registry地址,比如修改为淘宝镜像源。

npm set registry https://registry.npm.taobao.org/

如果有一天你肉身FQ到国外,用不上了,用rm命令删掉它

npm config rm registry

3.nrm 是专门用来管理和快速切换私人配置的 registry

建议全局安装

npm install nrm -g --save

nrm ls命令查看默认配置,带*号即为当前使用的配置

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/
npmMirror  https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/

也可以直接输入以下命令查看当前使用的是哪个源

nrm current

切换源

nrm use cnpm

用nrm add 命令添加公司私有npm源,如http://registry.npm.360.org(,起个别名叫qihoo

nrm add qihoo http://registry.npm.360.org

测试下速度

nrm test npm

输出

npm ---- 790ms

最后,如果你被公司开除了,怒删公司npm源配置

nrm del qihoo

4.更新Node版本和npm版本

清除node的cache(清除node的缓存,这个看情况而定,不是必须的)

sudo npm cache clean -f

安装"n"版本管理工具,管理node(没有错,就是n)

sudo npm install -g n

更新node版本

sudo npm install npm@latest -g

再查一遍本机当前Node和npm的版本吧

node -v
npm -v

推荐阅读