选择命令行版本:
🌐 Synopsis
npm
注意:此命令不支持工作区。
🌐 Note: This command is unaware of workspaces.
🌐 Version
9.9.4
🌐 Description
npm 是 Node JavaScript 平台的包管理器。它将模块放置到合适的位置,以便 Node 可以找到它们,并智能地管理依赖冲突。
🌐 npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently.
它具有极高的可配置性,可以支持多种使用场景。最常见的用法是用它来发布、发现、安装和开发 Node 程序。
🌐 It is extremely configurable to support a variety of use cases. Most commonly, you use it to publish, discover, install, and develop node programs.
运行 npm help 以获取可用命令列表。
🌐 Run npm help to get a list of available commands.
🌐 Important
npm 默认配置为使用 npm 的公共注册表,网址为 https://registry.npmjs.org。使用 npm 公共注册表需遵守 https://npm.nodejs.cn/policies/terms 上的使用条款。
🌐 npm comes preconfigured to use npm's public registry at https://registry.npmjs.org by default. Use of the npm public registry is subject to terms of use available at https://npm.nodejs.cn/policies/terms.
你可以配置 npm 使用任何你喜欢的兼容注册表,甚至可以运行你自己的注册表。使用他人的注册表需遵守其使用条款。
🌐 You can configure npm to use any compatible registry you like, and even run your own registry. Use of someone else's registry is governed by their terms of use.
🌐 Introduction
你可能获取 npm 因为你想安装东西。
🌐 You probably got npm because you want to install stuff.
在任何 Node 程序中,你最有可能首先运行的事情就是使用 npm install 来安装其依赖。
🌐 The very first thing you will most likely want to run in any node program is npm install to install its dependencies.
你也可以运行 npm install blerg 来安装最新版本的“blerg”。查看 npm install 获取更多信息。它可以做很多事情。
🌐 You can also run npm install blerg to install the latest version of "blerg". Check out npm install for more info. It can do a lot of stuff.
使用 npm search 命令显示公共注册表中可用的所有内容。使用 npm ls 显示你已安装的所有内容。
🌐 Use the npm search command to show everything that's available in the public registry. Use npm ls to show everything you've installed.
🌐 Dependencies
如果一个包在依赖中使用 git URL,npm 将使用 git 命令安装该依赖,如果未安装将会生成错误。
🌐 If a package lists a dependency using a git URL, npm will install that dependency using the git command and will generate an error if it is not installed.
如果 npm 尝试安装的某个包是原生 Node 模块并且需要编译 C++ 代码,npm 将使用 node-gyp 来完成该任务。对于 Unix 系统,node-gyp 需要 Python、make 和类似 GCC 的构建工具链。在 Windows 上,则需要 Python 和 Microsoft Visual Studio C++。更多信息请访问 node-gyp 仓库 和 node-gyp Wiki。
🌐 If one of the packages npm tries to install is a native node module and requires compiling of C++ Code, npm will use node-gyp for that task. For a Unix system, node-gyp needs Python, make and a buildchain like GCC. On Windows, Python and Microsoft Visual Studio C++ are needed. For more information visit the node-gyp repository and the node-gyp Wiki.
🌐 Directories
请参阅 folders 了解 npm 放置内容的位置。
🌐 See folders to learn about where npm puts stuff.
特别是,npm 有两种操作模式:
🌐 In particular, npm has two modes of operation:
./node_modules,可执行文件安装到 ./node_modules/.bin。$npm_config_prefix/lib/node_modules,并将可执行文件安装到 $npm_config_prefix/bin。本地模式是默认设置。使用任何命令中的 -g 或 --global 可改为全局模式运行。
🌐 Local mode is the default. Use -g or --global on any command to run in global mode instead.
🌐 Developer Usage
如果你使用 npm 开发和发布代码,请查看以下帮助主题:
🌐 If you're using npm to develop and publish your code, check out the following help topics:
package.json。npm link 来执行此操作。npm install 完成的npm publish 命令将你的代码上传到注册表。🌐 Configuration
npm 非常可配置。它从五个地方读取其配置选项。
🌐 npm is extremely configurable. It reads its configuration options from 5 places.
--key val 设置配置。所有键都需要一个值,即使它们是布尔类型(配置解析器在解析时不知道选项是什么)。如果你没有提供值(--key),那么该选项将被设置为布尔值 true。npm_config_ 前缀来设置任何配置。例如,export npm_config_key=val。$HOME/.npmrc 的文件是一个 ini 格式的配置列表。如果存在,将会被解析。如果在命令行或环境中设置了 userconfig 选项,将使用该文件。./etc/npmrc(相对于全局前缀)找到了该文件,将解析它。有关全局前缀的更多信息,请参阅 npm prefix。如果在命令行、环境变量或用户配置中设置了 globalconfig 选项,则会解析该文件。lib/utils/config/definitions.js 中。这些选项不得更改。有关更多信息,请参见 config。
🌐 See config for much much more information.
🌐 Contributions
欢迎补丁!
🌐 Patches welcome!
如果你想帮助,但不知道该做什么工作,请阅读贡献指南并查看问题列表。
🌐 If you would like to help, but don't know what to work on, read the contributing guidelines and check the issues list.
🌐 Bugs
当你发现问题时,请报告它们:https://github.com/npm/cli/issues
🌐 When you find issues, please report them: https://github.com/npm/cli/issues
请务必遵循模板和错误报告指南。
🌐 Please be sure to follow the template and bug reporting guidelines.
🌐 Feature Requests
在我们的论坛上讨论新特性的想法:
🌐 Discuss new feature ideas on our discussion forum:
或者建议正式的 RFC 提案:
🌐 Or suggest formal RFC proposals:
🌐 See Also