registry 配置
npm registry 原意为记录, 登记, 登记处的意思, 这里指的也就是 node 包存放的服务器地址.
查看 registry
- -> npm config get registry
- http://registry.npmjs.org // 默认 registry
修改为淘宝镜像
默认情况下我们执行 npm install * 这个命令时就是从 http://registry.npmjs.org 这个服务器上将 node 包下载到本地, 但该服务器在美国, 这样下载就会非常慢, 所以我们把 registry 改为国内淘宝镜像
npm config set registry http://registry.npm.taobao.org // 将 registry 设置为淘宝镜像
再次查看
- -> npm config get registry
- http://registry.npm.taobao.org // 已修改为淘宝镜像
注意
如果自己本地已经设置为淘宝镜像, 在 publish 本地 node 包时要改回原地址 不然会报 401 错误
npm config set registry http://registry.npmjs.org
一些命令
1. 查看当前目录下安装了哪些 node 包
npm ls
2. 登 6npm
- -> npm login
- Username: leinov
- Password:
- Email: (this IS public)
- Email: (this IS public) 1425795233@qq.com
- Logged in as leinov on http://registry.npmjs.org/.
3. 查看当前 npm 用户
- -> npm whoami
- leinov // 当前用户
如下提示表明还未登 6npm 该命令只在登 6 状态下使用, 或者使用 npm adduser 添加新用户
- npm ERR! code ENEEDAUTH
- npm ERR! need auth this command requires you to be logged in.
- npm ERR! need auth You need to authorize this machine using `npm adduser`
- npm ERR! A complete log of this run can be found in:
- npm ERR! /Users/leinov/.npm/_logs/2018-09-14T08_13_10_900Z-debug.log
4. 查看当前目录下安装了哪些 node 包
- -> npm ls
- xcx@1.0.0 /Users/*/node/xcx
└── axios@0.18.0 extraneous
5. 发布本地包
进入本地项目目录执行下面命令
- ```
- -> npm publish
- util@1.0.0 // 发布成功 可通过网页进入 npmjs.org 查看自己上传的包
- ```
来源: https://www.cnblogs.com/leinov/p/9658110.html