文件夹
选择命令行版本:
See Details
目录
描述
¥Description
npm 在你的计算机上放置各种东西。这就是它的工作。
¥npm puts various things on your computer. That's its job.
这份文件会告诉你它把什么放在哪里。
¥This document will tell you what it puts where.
tl;dr
-
本地安装(默认):将内容放入当前包根目录的
./node_modules中。¥Local install (default): puts stuff in
./node_modulesof the current package root. -
全局安装(使用
-g):将东西放在 /usr/local 或安装节点的任何地方。¥Global install (with
-g): puts stuff in /usr/local or wherever node is installed. -
如果你要对其进行
require(),请在本地安装。¥Install it locally if you're going to
require()it. -
如果要在命令行上运行它,请全局安装它。
¥Install it globally if you're going to run it on the command line.
-
如果两者都需要,那么在两个地方都安装,或者使用
npm link。¥If you need both, then install it in both places, or use
npm link.
前缀配置
¥prefix Configuration
prefix 配置 默认是安装 node 的位置。在大多数系统上,这是 /usr/local。在 Windows 上,它是 %AppData%\npm。在 Unix 系统上,它是上一级的,因为 node 通常安装在 {prefix}/bin/node 而不是 {prefix}/node.exe。
¥The prefix config defaults to the location where node is installed. On most systems, this is /usr/local. On Windows, it's %AppData%\npm. On Unix systems, it's one level up, since node is typically installed at {prefix}/bin/node rather than {prefix}/node.exe.
当设置 global 标志时,npm 会将内容安装到此前缀中。如果未设置,则使用当前包的根目录,如果不在包中,则使用当前工作目录。
¥When the global flag is set, npm installs things into this prefix. When it is not set, it uses the root of the current package, or the current working directory if not in a package already.
Node 模块
¥Node Modules
包被放到 prefix 下的 node_modules 文件夹中。在本地安装时,这意味着你可以 require("packagename") 加载它的主模块,或者 require("packagename/lib/path/to/sub/module") 加载其他模块。
¥Packages are dropped into the node_modules folder under the prefix. When installing locally, this means that you can require("packagename") to load its main module, or require("packagename/lib/path/to/sub/module") to load other modules.
Unix 系统上的全局安装转到 {prefix}/lib/node_modules。Windows 上的全局安装转到 {prefix}/node_modules(即没有 lib 文件夹。)
¥Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)
范围包的安装方式相同,除了它们被组合在相关 node_modules 文件夹的子文件夹中,并以 @ 符号作为该作用域前缀的名称,例如 npm install @myorg/package 会将包放在 {prefix}/node_modules/@myorg/package 中。有关详细信息,请参阅 scope。
¥Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package would place the package in {prefix}/node_modules/@myorg/package. See scope for more details.
如果你想 require() 一个包,那么在本地安装它。
¥If you wish to require() a package, then install it locally.
可执行文件
¥Executables
在全局模式下,可执行文件链接到 Unix 上的 {prefix}/bin,或直接链接到 Windows 上的 {prefix}。确保路径在终端的 PATH 环境中以运行它们。
¥When in global mode, executables are linked into {prefix}/bin on Unix, or directly into {prefix} on Windows. Ensure that path is in your terminal's PATH environment to run them.