1NPM 简介
1.1 NPM
Node.js? 是一个基于 Chrome V8 引擎的 JavaScript 运行时, 可方便地构建快速, 可扩展的网络应用程序的平台 Node.js 使用事件驱动, 非阻塞 I/O 模型, 轻量高效, 可以完美地处理时时数据, 运行在不同的设备上
从 Nodejs 官方网站的企业登记页, 包括我们熟知的公司有 LinkedIn, Yahoo, Paypal, eBay, Walmart,Groupon 还有很多的中小型公司, 国内的公司如雪球淘宝网易百度等也都有很多项目运行在 Node.js 之上
它的包生态系统, npm, 是目前世界上最大的开源库生态系统
NPM(node package manager), 通常称为 node 包管理器使用 NPM 可以对 node 包进行安装卸载更新查看搜索发布等操作安装完 Node.js,NPM 就可以直接用了
Node.js 官网
Node.js 中文网
2NPM 环境配置
2.1 安装 Node.js
从下面的地址中下载安装 Node.js
Node.js 官网下载地址
Node.js 其它下载地址 (node v9.7.1), 密码: svmp
或者直接使用 Homebrew 按照下面的命令安装 Node.js
- # 安装 Node.js
- $ brew install node
2.2 安装 NPM
安装完 Node.js,NPM 就可以直接用了
2.3 NPM 常用命令
1)NPM 常用命令
- # 查看 NPM 版本
- $ npm -v
- # 更新 NPM 版本
- $ sudo npm i -g npm
- # 安装包, 安装保存你项目 package.json 文件中的包
- $ npm install
- # 安装包, 安装在本地项目中
$ npm install [包名]
- $ npm install express
- # 安装包, 安装在全局中
$ npm install -g [包名]
- $ npm install -g express
- # 安装包, 并且将其保存你项目中的 package.json 文件
$ npm install [包名] --save
- $ npm install express --save
- # 查看安装的包, 本地
- $ npm list
- # 查看安装的包, 全局
- $ npm list -g
- # 查看过期的包, 本地
- $ npm outdated
- # 查看过期的包, 全局
- $ npm outdated -g
- # 更新全部包
- $ npm update
- # 更新指定的包
$ npm update [包名]
- $ npm update express
- # 卸载包
$ npm uninstall [包名]
- $ npm uninstall express
- Usage: npm <command>
- where <command> is one of:
- access, adduser, bin, bugs, c, cache, completion, config,
- ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
- explore, get, help, help-search, i, init, install,
- install-test, it, link, list, ln, login, logout, ls,
- outdated, owner, pack, ping, prefix, profile, prune,
- publish, rb, rebuild, repo, restart, root, run, run-script,
- s, se, search, set, shrinkwrap, star, stars, start, stop, t,
- team, test, token, tst, un, uninstall, unpublish, unstar,
- up, update, v, version, view, whoami
- npm <command> -h quick help on <command>
- npm -l display full usage info
- npm help <term> search for help on <term>
- npm help npm involved overview
- Specify configs in the ini-formatted file:
- /Users/qianchia/.npmrc
- or on the command line via: npm <command> --key value
- Config info can be viewed via: npm help config
2.4 注意事项
一般 Node modules 通常被安装在每个项目的本地文件夹 node_modules 中, 但下面几个包推荐安装在全局:
CoffeeScriptLessGrunt 或 Gulp
- # 安装 coffee-script
- $ npm install -g coffee-script
- # 安装 less
- $ npm install -g less
- # 安装 grunt-cli
- $ npm install -g grunt-cli
- # 安装 gulp
- $ npm install -g gulp
来源: http://www.bubuko.com/infodetail-2521884.html