使用nrm管理和使用 npm 私有仓储

110 阅读1分钟

安装 nrm

npm install -g nrm

使用 nrm

nrm 安装好了后可以使用 nrm ls 查看可选的源

$ nrm ls

* npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/

使用 nrm use <源> 可以切换源,例如切换成 cnpm 的源:

$ nrm use cnpm

    Registry has been set to: http://r.cnpmjs.org/

使用 nrm add <源> < http://***.com/ > 可以添加源

添加私有 npm 镜像服务器的源

$ nrm add myUrl http://192.168.66.72:3000/

    add registry myUrl success
$ nrm ls

  npm ---------- https://registry.npmjs.org/

  yarn --------- https://registry.yarnpkg.com/

  tencent ------ https://mirrors.cloud.tencent.com/npm/

  cnpm --------- https://r.cnpmjs.org/

  taobao ------- https://registry.npmmirror.com/

  npmMirror ---- https://skimdb.npmjs.com/registry/

  myUrl ---------- http://192.168.66.72:3000/

使用私有 npm 镜像服务器的源

$ nrm use myUrl

   Registry has been set to: http://192.168.66.72:3000/
$ nrm ls

  npm ---------- https://registry.npmjs.org/

  yarn --------- https://registry.yarnpkg.com/

  tencent ------ https://mirrors.cloud.tencent.com/npm/

  cnpm --------- https://r.cnpmjs.org/

  taobao ------- https://registry.npmmirror.com/

  npmMirror ---- https://skimdb.npmjs.com/registry/

* myUrl ---------- http://192.168.66.72:3000/

添加用户到私有 npm 镜像服务器

$ npm addUser

npm notice Log in on http://192.168.66.72:3000/

Username: zky

Password: 

Email: (this IS public) ***@163.com

Logged in as zky on http://192.168.66.72:3000/.

作用 npm addUser 添加用户成功后我们可以 使用 npm login 进行登录

$ npm login

npm notice Log in on http://192.168.66.72:3000/

Username: zky

Password: 

Email: (this IS public) ***@163.com

Logged in as zky on http://192.168.66.72:3000/.

查看npm当前用户和当前源

查看当前用户

$ npm who am i

查看当前源

$ npm config get registry

备注:如果使用的是yarn,可以安装yrm。

参考【使用 verdaccio 搭建 npm 镜像服务器