Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

npm-命令

  • 管理模块

    • 安装
      npm install <模块名>@x.x.x  参数
      
      • @x.x.x 可以指定版本
      • 参数
        • -S 等价于--save,写入到package.js的dependencies中
        • -D 等价于--save-dev,写入到package.js的devDependencies中
        • -g 表示全局安装
    • 卸载
      npm uninstall <模块名>  参数
      
    • 查看所有已安装的
      npm ls
      
    • 查看已安装的是否过时
      npm outdated
      
    • 升级
      npm update <模块名>
      
    • 查找信息
      npm search <模块名>
      
    • 浏览信息
      • 查看依赖
        npm view <模块名> dependencies
        
      • 查看源文件地址
        npm view <模块名> repository.url
        
    • 查看安装路径
      npm root
      
  • 直接运行Scripts

    npm run <command>
    
  • 设置代理

    npm config set proxy=http://xxx
    
  • 加速方法

    • 换国内npm源加速

      • 查看当前源
        npm config get registry
        
      • 换成淘宝源
        npm config set registry https://registry.npm.taobao.org/
        
    • 使用替代品加速

      • 用nrm管理源,并换成淘宝源
        npm install -g nrm
        nrm ls
        nrm use taobao
        nrm test taobao
        
      • 或者直接用cnpm命令替换
        npm install -g cnpm --registry=https://registry.npm.taobao.org