npm 学习笔记
一、初识npm文档
1.1 npm是啥?
npm 是 Node 的模块管理器,它是 Node 获得成功的重要原因之一。
官方文档翻译:npm是世界上最大的软件注册机构,开源开发人员使用npm来共享和借用包,许多组织也使用npm来管理私有开发;包括web、cli、registry三个部分
web——可以搜索包,管理个人信息和包管理等
cli——运行在命令行,程序猿和npm进行交互
registry——JS包大型公共数据库(npm 模块仓库提供了一个查询服务)
1.2 用npm 可以干啥?
- 管理自己代码的包
- 不需要npx即可运行包
- 分享代码
- 创建组织协调包维护,编码和开发人员。
- 管理代码版本和依赖
- 当底层代码更新时可以轻松更新应用程序。
1.3 package和nodemodules
区别:官方解释:
> package:A package is a file or directory that is described by a package.json file.
> nodeModule:A module is any file or directory in the node_modules directory that can be loaded by the Node.js *require()* function. To be loaded by the Node.js *require()* function, a module must be **one of the following**:
1.A folder with a package.json file containing a "main" field.
2.A folder with an index.js file in it.
3.A JavaScript file.(module 参考Node.js 模块)
注意:因为modules不要求有 package.json, 所以不是所有的 modules都是package. 只有modules 有package.json文件才是package.
>scopes:scopes允许您创建与其他用户/组织创建的包具有相同名称的包,而不会发生冲突。