npm常用命令总结

284 阅读1分钟

一.包管理

npm init

npm install 包名 –g (uninstall,update)

npm install 包名 --save-dev (uninstall,update)

npm list -g (不加-g,列举当前目录下的安装包)

npm info 包名(详细信息) npm info 包名 version(获取最新版本)

npm install md5@1(安装指定版本)

npm outdated(  检查包是否已经过时)

"dependencies": { "md5": "^2.1.0" } ^ 表示 如果 直接npm install 将会 安md5 2.*.* 最新版本 
"dependencies": { "md5": "~2.1.0" } ~ 表示 如果 直接npm install 将会 安装md5 2.1.* 最新版本 
"dependencies": { "md5": "*" } * 表示 如果 直接npm install 将会 安装

二.npm换源

  1. 查看当前源
    npm config get registry

  2. 更换npm源为国内淘宝镜像
    npm config set registry registry.npm.taobao.org/

  3. 更换npm源为国内npm官方镜像
    npm config set registry registry.cnpmjs.org/

  4. 还原npm源
    npm config set registry registry.npmjs.org/

  5. 源列表
    npm 官方原始镜像网址是:registry.npmjs.org/
    淘宝 NPM 镜像:registry.npm.taobao.org/
    阿里云 NPM 镜像:npm.aliyun.com
    腾讯云 NPM 镜像:mirrors.cloud.tencent.com/npm/
    华为云 NPM 镜像:mirrors.huaweicloud.com/repository/…
    网易 NPM 镜像:mirrors.163.com/npm/
    中科院大学开源镜像站:mirrors.ustc.edu.cn/
    清华大学开源镜像站:mirrors.tuna.tsinghua.edu.cn/

三.nrm换源

  1. 全局安装nrm
    npm install nrm -g --save

  2. nrm有默认配置使用 nrm ls 查看,带 * 即为当前源地址 image.png

  3. nrm切换淘宝镜像
    nrm use taobao

  4. 测试镜像速度
    nrm test taobao

  5. 使用nrm添加镜像地址
    nrm add r_name r_url // r_name 为镜像名字,r_url 为镜像地址

  6. 删除nrm镜像
    nrm del r_name