npm常用命令

398 阅读1分钟

清除缓存

npm cache clean --force

和淘宝镜像相关

npm install --registry=https://registry.npm.taobao.org // 临时使用淘宝镜像install
npm --registry https://registry.npm.taobao.org install express // 使用临时淘宝镜像install某个模块
npm install -g cnpm --registry=https://registry.npm.taobao.org  // 全局安装淘宝镜像,之后可以直接使用cnpm install

npm换源

npm --registry https://registry.npm.taobao.org install express // 临时使用淘宝镜像
npm config set registry https://registry.npm.taobao.org // 永久设置npm为淘宝镜像
npm config set registry https://registry.npmjs.org/ // 使用官方的镜像
npm config get registry // 查看npm源地址

更新npm版本

由于npm很多时候,我们是通过安装node来进行安装的,所以这个问题我们转换成如何管理node的版本。

npm install -g n    // 安装n
n stable    // 将n升级到稳定版本
n [node的版本号]    // 安装特定版本的npm

如果我们只是想单独升级npm的话,可以使用如下命令进行:

cnpm install -g npm@5.0.1

重装npm

npm install -g npm

升级npm到最新版本

npm install npm @latest -g