2019-05-18:npm的使用

npm的使用

by草梅友仁

参考链接https://www.runoob.com/nodejs/nodejs-npm.html

安装

由于新版的nodejs已经集成了npm,所以之前npm也一并安装好了。同样可以通过输入 "npm -v" 来测试是否成功安装。命令如下,出现版本提示表示安装成功:

npm -v
image

如果你安装的是旧版本的 npm,可以很容易得通过 npm 命令来升级,命令如下:

#Linux
sudo npm install npm -g
#Windows
npm install npm -g

使用 npm 命令安装模块

npm 安装 Node.js 模块语法格式如下:

npm install 

全局安装与本地安装

npm install express      # 本地安装
npm install express -g   # 全局安装

卸载模块

我们可以使用以下命令来卸载 Node.js 模块。

npm uninstall express

更新模块

我们可以使用以下命令更新模块:

npm update express

搜索模块

使用以下来搜索模块:

npm search express

使用淘宝 NPM 镜像

你可以使用淘宝定制的 cnpm (gzip 压缩支持) 命令行工具代替默认的 npm:

npm install -g cnpm --registry=https://registry.npm.taobao.org

这样就可以使用 cnpm 命令来安装模块了:

cnpm install [name]

更多信息可以查阅:http://npm.taobao.org/。

你可能感兴趣的:(2019-05-18:npm的使用)