NPM 命令

npm 命令解析

 

  • 查看 npm 版本
    npm -v
  • 查看全局安装的模块(包)
    npm list -g 
  • 全局安装 express 包
    npm install express -g
  • 卸载全局安装包
    npm uninstall express -g
  • 在项目中安装项目依赖包
    npm install bootstrap --save
  • 在项目中安装开发依赖包,非项目依赖
    npm install typescript --save-dev
  • 查看包的更新情况
    npm outdated [-g]
  • 更新包(若无效,使用安装包命令)
    npm update express
  • 查看包在 npm 上发过哪些版本以及最新的版本
    npm info react
  • 列出包发过哪些 tag
    npm dist-tag ls react
  • 查看帮助
    npm help
  • 清除缓存
    npm cache clean
  • 清理代码
    npm prune

npm 配置

  • 查看所有配置
    npm config list
  • 直接修改配置文件
    npm config edit
  • 设置 proxy
    npm config set proxy http://proxy.example.com:8000
  • 查看 proxy
    npm config get proxy
  • 删除 proxy
    npm delete proxy
  • 国内可以使用 cnpm 代替 npm,速度会快很多
    npm install -g cnpm --registry=https://registry.npm.taobao.org

nrm 快速切换 npm 源

  • 列出可选的源
    nrm ls
  • 切换到 taobao
    nrm use taobao
  • 测试所有源的响应时间
    nrm test

node 更新

  • 安装 n 模块
    sudo npm install n -g
  • 更新 node 至最新版
    sudo n stable
原文地址:https://www.cnblogs.com/Hao-Killer/p/7235398.html