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.
PHP
Tools similar to :Composer
. It is a package manager for PHP that can be used to download, install and manage PHP dependencies, similar to npm.Java
Tools 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.Python
Tools similar to :pip
. It is a package manager for Python that can be used to install and manage Python dependencies, similar to npm.Rust
Tools 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
npm init
: Initialize a new npm project and create a package.json file.npm install
: Install a package or a set of packages, and store a node_modules in the current directory.npm install <package-name>
: Install the specified package.npm install <package-name> --save
: Install the specified package and add it to the list of dependencies in the package.json file.npm install <package-name> --save-dev
: Install the specified package and add it to the list of development dependencies in the package.json file.npm install -g <package-name>
: Install the specified package globally.npm update <package-name>
: Update the specified package.npm uninstall <package-name>
: Uninstall the specified package.npm run <script-name>
: Execute the script command defined in the package.json file.npm search <keyword>
: Search for packages containing the specified keyword in the npm library.npm info <package-name>
: View the detailed information of the specified package.npm list
: List all packages installed in the current project.npm outdated
: List the packages that need to be updated in the current project.npm audit
: Check dependencies in the current project for security vulnerabilities.npm publish
: Publish self-developed packages to the npm library.npm login
: Log in to the npm account.npm logout
:注销当前 npm 账户。npm link
: 将本地模块链接到全局的node_modules
目录下npm config list
用于列出所有的 npm 配置信息。执行该命令可以查看当前系统和用户级别的所有 npm 配置信息,以及当前项目的配置信息(如果在项目目录下执行该命令)npm get registry
用于获取当前 npm 配置中的 registry 配置项的值。registry 配置项用于指定 npm 包的下载地址,如果未指定,则默认使用 npm 官方的包注册表地址npm set registry
npm config set registry <registry-url>
命令,将 registry 配置项的值修改为指定的<registry-url>
地址
Package json
执行npm init 便可以初始化一个package.json
name
:项目名称,必须是唯一的字符串,通常采用小写字母和连字符的组合。version
:项目版本号,通常采用语义化版本号规范。description
:项目描述。main
:项目的主入口文件路径,通常是一个 JavaScript 文件。keywords
:项目的关键字列表,方便他人搜索和发现该项目。author
:项目作者的信息,包括姓名、邮箱、网址等。license
:项目的许可证类型,可以是自定义的许可证类型或者常见的开源许可证(如 MIT、Apache 等)。dependencies
:项目所依赖的包的列表,这些包会在项目运行时自动安装。devDependencies
:项目开发过程中所需要的包的列表,这些包不会随项目一起发布,而是只在开发时使用。peerDependencies
:项目的同级依赖,即项目所需要的模块被其他模块所依赖。scripts
:定义了一些脚本命令,比如启动项目、运行测试等。repository
:项目代码仓库的信息,包括类型、网址等。bugs
:项目的 bug 报告地址。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