Nodejs Chapter 3 (Npm Package json)

npm

npm(full name Node Package Manager) is a package management tool for Node.js. It is a command-line based tool to help developers install, upgrade, remove and manage dependencies in their projects.

www.npmjs.com/

  • PHPTools similar to : Composer. It is a package manager for PHP that can be used to download, install and manage PHP dependencies, similar to npm.
  • JavaTools similar to : Maven. It is a build tool and project management tool for Java that automates building, testing, and deploying Java applications, similar to what npm and webpack do.
  • PythonTools similar to : pip. It is a package manager for Python that can be used to install and manage Python dependencies, similar to npm.
  • RustTools similar to : Cargo. It is Rust's package manager and build tool, which can be used to download, compile and manage Rust's dependencies, similar to the functions of npm and Maven.

npm command

  1. npm init: Initialize a new npm project and create a package.json file.
  2. npm install: Install a package or a set of packages, and store a node_modules in the current directory.
  3. npm install <package-name>: Install the specified package.
  4. npm install <package-name> --save: Install the specified package and add it to the list of dependencies in the package.json file.
  5. npm install <package-name> --save-dev: Install the specified package and add it to the list of development dependencies in the package.json file.
  6. npm install -g <package-name>: Install the specified package globally.
  7. npm update <package-name>: Update the specified package.
  8. npm uninstall <package-name>: Uninstall the specified package.
  9. npm run <script-name>: Execute the script command defined in the package.json file.
  10. npm search <keyword>: Search for packages containing the specified keyword in the npm library.
  11. npm info <package-name>: View the detailed information of the specified package.
  12. npm list: List all packages installed in the current project.
  13. npm outdated: List the packages that need to be updated in the current project.
  14. npm audit: Check dependencies in the current project for security vulnerabilities.
  15. npm publish: Publish self-developed packages to the npm library.
  16. npm login: Log in to the npm account.
  17. npm logout:注销当前 npm 账户。
  18. npm link: 将本地模块链接到全局的 node_modules 目录下
  19. npm config list 用于列出所有的 npm 配置信息。执行该命令可以查看当前系统和用户级别的所有 npm 配置信息,以及当前项目的配置信息(如果在项目目录下执行该命令)
  20. npm get registry 用于获取当前 npm 配置中的 registry 配置项的值。registry 配置项用于指定 npm 包的下载地址,如果未指定,则默认使用 npm 官方的包注册表地址
  21. npm set registry npm config set registry <registry-url> 命令,将 registry 配置项的值修改为指定的 <registry-url> 地址

Package json

执行npm init 便可以初始化一个package.json

  1. name:项目名称,必须是唯一的字符串,通常采用小写字母和连字符的组合。
  2. version:项目版本号,通常采用语义化版本号规范。
  3. description:项目描述。
  4. main:项目的主入口文件路径,通常是一个 JavaScript 文件。
  5. keywords:项目的关键字列表,方便他人搜索和发现该项目。
  6. author:项目作者的信息,包括姓名、邮箱、网址等。
  7. license:项目的许可证类型,可以是自定义的许可证类型或者常见的开源许可证(如 MIT、Apache 等)。
  8. dependencies:项目所依赖的包的列表,这些包会在项目运行时自动安装。
  9. devDependencies:项目开发过程中所需要的包的列表,这些包不会随项目一起发布,而是只在开发时使用。
  10. peerDependencies:项目的同级依赖,即项目所需要的模块被其他模块所依赖。
  11. scripts:定义了一些脚本命令,比如启动项目、运行测试等。
  12. repository:项目代码仓库的信息,包括类型、网址等。
  13. bugs:项目的 bug 报告地址。
  14. homepage:项目的官方网站地址或者文档地址。

version 三段式版本号一般是1.0.0 大版本号 次版本号 修订号, 大版本号一般是有重大变化才会升级, 次版本号一般是增加功能进行升级, 修订号一般是修改bug进行升级

When npm install installs modules, it is generally installed flat, but sometimes nesting occurs because of different versions. A depends on C1.0, B depends on C1.0, and D depends on C2.0. At this time, C 1.0 will be replaced Put it into the node_moduels of AB, C2.0 will be put into the node_moduels under the D module

Guess you like

Origin juejin.im/post/7260819638123184185