npm 安装与使用过程

前端 共 648 字,约 2 分钟

本章主要介绍npm。


1.1 简介

npm 是 Node.js 的包管理工具, 是世界上最大的开源库生态系统。


1.2 安装

新版的nodejs 已经集成了npm, 所以只需 安装nodeJS 即可


1.3 npm升级

  • windows:
    sudo npm install npm -g
  • linux:
    npm install npm -g

1.4 使用nrm切换npm源

npm是包管理工具, 官方默认npm源是 https://registry.npmjs.org/, 国内直接使用非常慢, 可以切换为国内的npm源, 使用nrm切换npm源非常方便。

  • 安装nrm
    npm install -g nrm
  • 列出所有npm源
    nrm ls
  • 当前使用的npm源
    nrm current
  • 切换为淘宝npm源
    nrm use https://registry.npm.taobao.org/
  • 添加淘宝npm源
    nrm add taobao https://registry.npm.taobao.org/
  • 删除淘宝npm源
    nrm del https://registry.npm.taobao.org/
  • 测试淘宝npm源速度
    nrm test https://registry.npm.taobao.org/

1.5 npm 命令

  • 使用 npm 命令安装模块,命令中加上-g代表全局安装
    npm install <Module Name> [-g]
  • 卸载模块
    npm uninstall <Module Name>
  • 更新模块
    npm update <Module Name>
  • 搜索模块
    npm search <Module Name>

文档信息

搜索

    Table of Contents