npm常用命令

1. 构建项目

  • 创建package.json
npm init
# 全部使用默认配置
npm init --yes

2. 安装包

# 全局安装
npm install 包名 -g
# 本地安装
npm install 包名
# 一次安装多个
npm install 包123 --save
# 安装运行时依赖包,--save会将包引入到package.json中
npm install 包名 --save

3. 查看安装目录

# 本地安装目录
npm root
# 全局安装目录
npm root -g

4. 卸载包

# 本地
npm uninstall 包名
# 全局
npm uninstall 包名 -g

5. 更新包

npm update 包名
npm update 包名 -g

6. 查看已安装的包

npm ls
npm ls -g

7. 使用国内npm镜像源

  1. 使用配置
npm config set registry https://registry.npm.taobao.org

查看

npm config get registry
  1. 使用cnpm
# 安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 使用cnpm
cnpm install 包名

8. 使用yarn

  • npm和yarn同为node.js的依赖管理工具,功能相同,但是yarn的下载和启动速度比npm快
# 安装yarn
npm install -g yarn --registry=https://registry.npm.taobao.org
  • 安装yarn后需要添加环境变量,这里安装后的目录是C:\Users\admin\AppData\Local\Yarn\bin,替换成你自己的

在这里插入图片描述

ValueValue
初始化npm inityarn init
安装依赖npm install xxxyarn install
安装依赖并保存npm install xxx --saveyarn add xxx
安装全局依赖npm install -g xxxyarn global add xxx
移除依赖npm uninstall xxxyarn remove xxx
更新依赖npm update xxxyarn upgrade xxx
运行指令npm runyarn run

9. 查看配置

#全局配置
npm config list

10. 配置代理

npm config set proxy http://server:port
npm config set https-proxy http://server:port
  • 查看代理
npm config get proxy
npm config get https-proxy
  • 删除代理
npm config delete proxy
npm config delete https-proxy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fisher3652

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值