安装
- 
精确安装最新版本
npm install --save-exact 包名 npm install -E 包名 - 
安装指定版本
npm install 包名@版本号 
查询
- 
查询包安装路径
# -g 表示全局路径 npm root [-g] - 
查看包信息
# 以下方式等价,子信息是 package.json 中的字段 npm view 包名 [子信息] npm v 包名 [子信息] npm info 包名 [子信息] npm show 包名 [子信息] # 查看 react 包的 name、versions npm show react name npm show react versions - 
查询安装包
# -g 全局 # depth 深度从 0 开始 npm list [-g] [--depth=依赖深度] npm ls [-g] [--depth=依赖深度] npm la [-g] [--depth=依赖深度] npm ll [-g] [--depth=依赖深度] 
更新
- 
检查有哪些包需要更新
npm outdated - 
更新包
# 以下方式等价 npm update [-g] [包名] npm up [-g] [包名] npm upgrade [-g] [包名] 
卸载包
# 以下方式等价
npm uninstall [-g] 包名
npm remove [-g] 包名
npm rm [-g] 包名
npm r [-g] 包名
npm un [-g] 包名
npm unlink [-g] 包名
npm 配置
- 
npm 的配置会对其他命令产生或多或少的影响
 - 
安装好 npm 之后,最终会产生两个配置文件,一个是用户配置,一个是系统配置,当两个文件的配置项有冲突的时候,用户配置会覆盖系统配置
 - 
通常,我们不关心具体的配置文件,而只关心最终生效的配置
 - 
通过下面的命令可以查询目前生效的各种配置
npm config ls [-l] [--json] - 
可以通过下面的命令操作配置
- 获取某个配置项
npm config get 配置项 - 设置某个配置项
npm config set 配置项=值 - 移除某个配置项
npm config delete 配置项 
 - 获取某个配置项
 
npm👉 运行环境配置
上一篇