npm的中文网:www.npmjs.com.cn/
模块:js文件 ----> commonjs规范
包:把多个模块组织到一个目录中,该目录中有package.json(包的描述文件)
npm的作用是什么?
组织和管理 node的包
1>安装
2>卸载
3>查看
4>使用
5>更新 npm update <包名> -S/-D/-g
安装的基本流程
1>去对应的网站https://registry.npmjs.org/<包名>(镜像源)进行查询
2>下载对应包的压缩包到缓存目录
npm config get cache 查看缓存目录
3>解压到对应的目录
本地安装
1.开发环境
npm install 包 --save-dev
npm install 包 -D
2.生产环境
npm install 包 --save
npm install 包 -S
3>全局安装
npm install 包 -g
npm root -g 查看全局安装的目录
4>卸载包
npm uninstall 包 本地/全局
5>设置当前使用的镜像源
npm config get registry 获取镜像源
npm config set registry registry.npm.taobao.org
6>根据依赖安装
根据package.json里的依赖去安装,执行npm install
7>Commonjs require的查找机制
8>NODE_PATH的配置和作用
指定一个路径,供require查找来使用的
npm常用的命令
npm -v
npm init
npm install
npm search <包名> 搜索包是否存在
npm config list npm配置总览
npm config get/set registry 查看/设置当前的镜像源
npm root -g 查看全局包的安装位置
npm config get/set prefix 查看/设置全局包的安装位置
npm config get cache 查看缓存目录
npm cache clean -f 清除缓存