- assert 断言
- async_hooks 异步钩子
- async_hooks/context 异步上下文
- buffer 缓冲区
- C++插件
- C/C++插件(使用 Node-API)
- C++嵌入器
- child_process 子进程
- cluster 集群
- CLI 命令行
- console 控制台
- Corepack 核心包
- crypto 加密
- crypto/webcrypto 网络加密
- debugger 调试器
- deprecation 弃用
- dgram 数据报
- diagnostics_channel 诊断通道
- dns 域名服务器
- domain 域
- Error 错误
- events 事件触发器
- fs 文件系统
- global 全局变量
- http 超文本传输协议
- http2 超文本传输协议 2.0
- https 安全超文本传输协议
- inspector 检查器
- Intl 国际化
- module 模块
- module/cjs CommonJS 模块
- module/esm ECMAScript 模块
- module/package 包模块
- net 网络
- os 操作系统
- path 路径
- perf_hooks 性能钩子
- permission 权限
- process 进程
- punycode 域名代码
- querystring 查询字符串
- readline 逐行读取
- repl 交互式解释器
- report 诊断报告
- stream 流
- stream/web 网络流
- string_decoder 字符串解码器
- test 测试
- timers 定时器
- tls 安全传输层
- trace_events 跟踪事件
- tty 终端
- url 网址
- util 实用工具
- v8 引擎
- vm 虚拟机
- wasi 网络汇编系统接口
- worker_threads 工作线程
- zlib 压缩
Node.js v16.20.2 文档
- Node.js v16.20.2
-
目录
- 命令行 API
- 概要
- 程序入口点
- 选项
-----abort-on-uncaught-exception--completion-bash-C=条件,--conditions=条件--cpu-prof--cpu-prof-dir--cpu-prof-interval--cpu-prof-name--diagnostic-dir=directory--disable-proto=mode--disallow-code-generation-from-strings--dns-result-order=order--enable-fips--enable-source-maps--experimental-fetch--experimental-global-customevent--experimental-global-webcrypto--experimental-import-meta-resolve--experimental-loader=module--experimental-network-imports--experimental-policy--no-experimental-repl-await--experimental-specifier-resolution=mode--experimental-vm-modules--experimental-wasi-unstable-preview1--experimental-wasm-modules--force-context-aware--force-fips--frozen-intrinsics--force-node-api-uncaught-exceptions-policy--heapsnapshot-near-heap-limit=max_count--heapsnapshot-signal=signal--heap-prof--heap-prof-dir--heap-prof-interval--heap-prof-name--icu-data-dir=file--input-type=type--inspect-brk[=[host:]port]--inspect-port=[host:]port--inspect[=[host:]port]--inspect-publish-uid=stderr,http--insecure-http-parser--jitless--max-http-header-size=size--napi-modules--no-addons--no-deprecation--no-force-async-hooks-checks--no-global-search-paths--no-warnings--node-memory-debug--openssl-config=file--openssl-shared-config--openssl-legacy-provider--pending-deprecation--policy-integrity=sri--preserve-symlinks--preserve-symlinks-main--prof--prof-process--redirect-warnings=file--report-compact--report-dir=目录,report-directory=目录--report-filename=filename--report-on-fatalerror--report-on-signal--report-signal=signal--report-uncaught-exception--secure-heap=n--secure-heap-min=n--test--test-only--throw-deprecation--title=title--tls-cipher-list=list--tls-keylog=file--tls-max-v1.2--tls-max-v1.3--tls-min-v1.0--tls-min-v1.1--tls-min-v1.2--tls-min-v1.3--trace-atomics-wait--trace-deprecation--trace-event-categories--trace-event-file-pattern--trace-events-enabled--trace-exit--trace-sigint--trace-sync-io--trace-tls--trace-uncaught--trace-warnings--track-heap-objects--unhandled-rejections=mode--use-bundled-ca,--use-openssl-ca--use-largepages=mode--v8-options--v8-pool-size=num--watch--watch-path--zero-fill-buffers-c,--check-e,--eval "脚本"-h,--help-i,--interactive-p,--print "script"-r,--require 模块-v,--version
- 环境变量
FORCE_COLOR=[1, 2, 3]NODE_DEBUG=module[,…]NODE_DEBUG_NATIVE=module[,…]NODE_DISABLE_COLORS=1NODE_EXTRA_CA_CERTS=fileNODE_ICU_DATA=fileNODE_NO_WARNINGS=1NODE_OPTIONS=options...NODE_PATH=path[:…]NODE_PENDING_DEPRECATION=1NODE_PENDING_PIPE_INSTANCES=instancesNODE_PRESERVE_SYMLINKS=1NODE_REDIRECT_WARNINGS=fileNODE_REPL_HISTORY=fileNODE_REPL_EXTERNAL_MODULE=fileNODE_SKIP_PLATFORM_CHECK=valueNODE_TLS_REJECT_UNAUTHORIZED=valueNODE_V8_COVERAGE=dirNO_COLOR=<any>OPENSSL_CONF=fileSSL_CERT_DIR=dirSSL_CERT_FILE=fileTZUV_THREADPOOL_SIZE=size
- 有用的 V8 选项
- 命令行 API
-
导航
- assert 断言
- async_hooks 异步钩子
- async_hooks/context 异步上下文
- buffer 缓冲区
- C++插件
- C/C++插件(使用 Node-API)
- C++嵌入器
- child_process 子进程
- cluster 集群
- CLI 命令行
- console 控制台
- Corepack 核心包
- crypto 加密
- crypto/webcrypto 网络加密
- debugger 调试器
- deprecation 弃用
- dgram 数据报
- diagnostics_channel 诊断通道
- dns 域名服务器
- domain 域
- Error 错误
- events 事件触发器
- fs 文件系统
- global 全局变量
- http 超文本传输协议
- http2 超文本传输协议 2.0
- https 安全超文本传输协议
- inspector 检查器
- Intl 国际化
- module 模块
- module/cjs CommonJS 模块
- module/esm ECMAScript 模块
- module/package 包模块
- net 网络
- os 操作系统
- path 路径
- perf_hooks 性能钩子
- permission 权限
- process 进程
- punycode 域名代码
- querystring 查询字符串
- readline 逐行读取
- repl 交互式解释器
- report 诊断报告
- stream 流
- stream/web 网络流
- string_decoder 字符串解码器
- test 测试
- timers 定时器
- tls 安全传输层
- trace_events 跟踪事件
- tty 终端
- url 网址
- util 实用工具
- v8 引擎
- vm 虚拟机
- wasi 网络汇编系统接口
- worker_threads 工作线程
- zlib 压缩
- 其他版本
命令行 API#>
【Command-line API】
Node.js 提供了多种命令行选项。这些选项提供了内置调试、多种执行脚本的方式以及其他有用的运行时选项。
【Node.js comes with a variety of CLI options. These options expose built-in debugging, multiple ways to execute scripts, and other helpful runtime options.】
要在终端中将此文档作为手册页查看,请运行 man node。
【To view this documentation as a manual page in a terminal, run man node.】
概要#>
【Synopsis】
node [options] [V8 options] [<program-entry-point> | -e "script" | -] [--] [arguments]
node inspect [<program-entry-point> | -e "script" | <host>:<port>] …
node --v8-options
无需参数即可启动 REPL。
【Execute without arguments to start the REPL.】
有关 node inspect 的更多信息,请参阅 调试器 文档。
【For more info about node inspect, see the debugger documentation.】
程序入口点#>
【Program entry point】
程序的入口点是一个类似指定符的字符串。如果该字符串不是绝对路径,它将被解析为相对于当前工作目录的路径。然后,该路径由 CommonJS 模块加载器解析。如果找不到对应的文件,将抛出错误。
【The program entry point is a specifier-like string. If the string is not an absolute path, it's resolved as a relative path from the current working directory. That path is then resolved by CommonJS module loader. If no corresponding file is found, an error is thrown.】
如果找到文件,其路径将在以下任何情况下传递给 ECMAScript 模块加载器:
【If a file is found, its path will be passed to the ECMAScript module loader under any of the following conditions:】
- 该程序是使用命令行标志启动的,该标志强制使用 ECMAScript 模块加载器加载入口点。
- 该文件有一个
.mjs扩展名。 - 该文件没有
.cjs扩展名,并且最近的父级package.json文件包含一个顶层"type"字段,其值为 "module"。
否则,文件将使用 CommonJS 模块加载器加载。更多详情请参阅 模块加载器。
【Otherwise, the file is loaded using the CommonJS module loader. See Modules loaders for more details.】
ECMAScript 模块加载器入口点警告#>
【ECMAScript modules loader entry point caveat】
当加载 ECMAScript 模块加载器 加载程序入口点时,node 命令只接受扩展名为 .js、.mjs 或 .cjs 的文件作为输入;在启用 --experimental-wasm-modules 时,也可以接受扩展名为 .wasm 的文件。
【When loading ECMAScript module loader loads the program entry point, the node
command will only accept as input only files with .js, .mjs, or .cjs
extensions; and with .wasm extensions when
--experimental-wasm-modules is enabled.】
选项#>
【Options】
所有选项,包括 V8 选项,都允许单词通过连字符(-)或下划线(_)分隔。例如,--pending-deprecation 等同于 --pending_deprecation。
【All options, including V8 options, allow words to be separated by both
dashes (-) or underscores (_). For example, --pending-deprecation is
equivalent to --pending_deprecation.】
如果一个只接受单个值的选项(例如 --max-http-header-size)被多次传递,则使用最后传递的值。命令行中的选项优先于通过 NODE_OPTIONS 环境变量传递的选项。
【If an option that takes a single value (such as --max-http-header-size) is
passed more than once, then the last passed value is used. Options from the
command line take precedence over options passed through the NODE_OPTIONS
environment variable.】
-#>
stdin 的别名。类似于其他命令行工具中使用 - 的方式,表示脚本从 stdin 读取,其余选项传递给该脚本。
【Alias for stdin. Analogous to the use of - in other command-line utilities,
meaning that the script is read from stdin, and the rest of the options
are passed to that script.】
--#>
指示节点选项的结束。将其余的参数传递给脚本。如果在此之前没有提供脚本文件名或 eval/print 脚本,则下一个参数将作为脚本文件名使用。
【Indicate the end of node options. Pass the rest of the arguments to the script. If no script filename or eval/print script is supplied prior to this, then the next argument is used as a script filename.】
--abort-on-uncaught-exception#>
中止而不是退出会生成一个核心文件,用于使用调试器(如 lldb、gdb 和 mdb)进行事后分析。
【Aborting instead of exiting causes a core file to be generated for post-mortem
analysis using a debugger (such as lldb, gdb, and mdb).】
如果传递了此标志,行为仍然可以通过 process.setUncaughtExceptionCaptureCallback()(以及通过使用依赖它的 node:domain 模块)设置为不终止。
【If this flag is passed, the behavior can still be set to not abort through
process.setUncaughtExceptionCaptureCallback() (and through usage of the
node:domain module that uses it).】
--completion-bash#>
为 Node.js 打印可源代码的 bash 完成脚本。
【Print source-able bash completion script for Node.js.】
$ node --completion-bash > node_bash_completion
$ source node_bash_completion
-C=条件, --conditions=条件#>
【-C=condition, --conditions=condition】
启用对自定义 条件导出 分辨率条件的实验性支持。
【Enable experimental support for custom conditional exports resolution conditions.】
允许任意数量的自定义字符串条件名称。
【Any number of custom string condition names are permitted.】
默认的 Node.js 条件 "node"、"default"、"import" 和 "require" 将始终按定义应用。
【The default Node.js conditions of "node", "default", "import", and
"require" will always apply as defined.】
例如,要以“开发”配置运行一个模块:
【For example, to run a module with "development" resolutions:】
$ node -C=development app.js
--cpu-prof#>
在启动时启动 V8 CPU 分析器,并在退出前将 CPU 分析结果写入磁盘。
【Starts the V8 CPU profiler on start up, and writes the CPU profile to disk before exit.】
如果未指定 --cpu-prof-dir,生成的性能分析文件将放在当前工作目录中。
【If --cpu-prof-dir is not specified, the generated profile is placed
in the current working directory.】
如果未指定 --cpu-prof-name,生成的配置文件将命名为 CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile。
【If --cpu-prof-name is not specified, the generated profile is
named CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile.】
$ node --cpu-prof index.js
$ ls *.cpuprofile
CPU.20190409.202950.15293.0.0.cpuprofile
--cpu-prof-dir#>
指定由 --cpu-prof 生成的 CPU 分析文件将放置的目录。
【Specify the directory where the CPU profiles generated by --cpu-prof will
be placed.】
默认值由 --diagnostic-dir 命令行选项控制。
【The default value is controlled by the
--diagnostic-dir command-line option.】
--cpu-prof-interval#>
指定由 --cpu-prof 生成的 CPU 配置文件的采样间隔(微秒)。默认值是 1000 微秒。
【Specify the sampling interval in microseconds for the CPU profiles generated
by --cpu-prof. The default is 1000 microseconds.】
--cpu-prof-name#>
指定由 --cpu-prof 生成的 CPU 配置文件的文件名。
【Specify the file name of the CPU profile generated by --cpu-prof.】
--diagnostic-dir=directory#>
设置所有诊断输出文件写入的目录。默认是当前工作目录。
【Set the directory to which all diagnostic output files are written. Defaults to current working directory.】
影响默认输出目录:
【Affects the default output directory of:】
--disable-proto=mode#>
禁用 Object.prototype.__proto__ 属性。如果 mode 为 delete,则该属性将被完全移除。如果 mode 为 throw,访问该属性会抛出代码为 ERR_PROTO_ACCESS 的异常。
【Disable the Object.prototype.__proto__ property. If mode is delete, the
property is removed entirely. If mode is throw, accesses to the
property throw an exception with the code ERR_PROTO_ACCESS.】
--disallow-code-generation-from-strings#>
让像 eval 和 new Function 这样的内置语言特性在从字符串生成代码时抛出异常。这不会影响 Node.js 的 node:vm 模块。
【Make built-in language features like eval and new Function that generate
code from strings throw an exception instead. This does not affect the Node.js
node:vm module.】
--dns-result-order=order#>
设置 dns.lookup() 和 dnsPromises.lookup() 中 verbatim 的默认值。该值可以是:
【Set the default value of verbatim in dns.lookup() and
dnsPromises.lookup(). The value could be:】
ipv4first:将默认verbatim设置为false。verbatim:将默认verbatim设置为true。
默认值是 ipv4first,dns.setDefaultResultOrder() 的优先级高于 --dns-result-order。
【The default is ipv4first and dns.setDefaultResultOrder() have higher
priority than --dns-result-order.】
--enable-fips#>
在启动时启用符合 FIPS 的加密。(需要使用支持 FIPS 的 OpenSSL 构建 Node.js。)
【Enable FIPS-compliant crypto at startup. (Requires Node.js to be built against FIPS-compatible OpenSSL.)】
--enable-source-maps#>
启用 源映射 v3 支持堆栈跟踪。
【Enable Source Map v3 support for stack traces.】
当使用像 TypeScript 这样的转译器时,应用抛出的堆栈跟踪会引用转译后的代码,而不是原始源代码位置。--enable-source-maps 启用源映射的缓存,并尽最大努力报告相对于原始源文件的堆栈跟踪。
【When using a transpiler, such as TypeScript, stack traces thrown by an
application reference the transpiled code, not the original source position.
--enable-source-maps enables caching of Source Maps and makes a best
effort to report stack traces relative to the original source file.】
重写 Error.prepareStackTrace 会阻止 --enable-source-maps 修改堆栈跟踪。
【Overriding Error.prepareStackTrace prevents --enable-source-maps from
modifying the stack trace.】
注意,启用源映射可能会在访问 Error.stack 时增加应用的延迟。如果你的应用中频繁访问 Error.stack,请考虑 --enable-source-maps 的性能影响。
【Note, enabling source maps can introduce latency to your application
when Error.stack is accessed. If you access Error.stack frequently
in your application, take into account the performance implications
of --enable-source-maps.】
--experimental-fetch#>
启用对 获取 API 的实验性支持。
【Enable experimental support for the Fetch API.】
--experimental-global-customevent#>
将 自定义事件 Web API 暴露在全局作用域中。
【Expose the CustomEvent Web API on the global scope.】
--experimental-global-webcrypto#>
将 网络加密 API 暴露在全局作用域中。
【Expose the Web Crypto API on the global scope.】
--experimental-import-meta-resolve#>
启用实验性的 import.meta.resolve() 支持。
【Enable experimental import.meta.resolve() support.】
--experimental-loader=module#>
指定自定义实验 ECMAScript 模块加载器 的 module。
module 可以是任何 import 说明符 接受的字符串。
【Specify the module of a custom experimental ECMAScript module loader.
module may be any string accepted as an import specifier.】
--experimental-network-imports#>
在 import 指定符中启用对 https: 协议的实验性支持。
【Enable experimental support for the https: protocol in import specifiers.】
--experimental-policy#>
使用指定的文件作为安全策略。
【Use the specified file as a security policy.】
--no-experimental-repl-await#>
使用此标志在交互式解释器中禁用顶层等待。
【Use this flag to disable top-level await in REPL.】
--experimental-specifier-resolution=mode#>
设置用于解析 ES 模块标识符的解析算法。有效选项是 explicit 和 node。
【Sets the resolution algorithm for resolving ES module specifiers. Valid options
are explicit and node.】
默认值是 explicit,这要求提供模块的完整路径。node 模式支持可选的文件扩展名,并且能够导入具有索引文件的目录。
【The default is explicit, which requires providing the full path to a
module. The node mode enables support for optional file extensions and
the ability to import a directory that has an index file.】
有关示例用法,请参见 自定义 ESM 指定符解析。
【See customizing ESM specifier resolution for example usage.】
--experimental-vm-modules#>
在 node:vm 模块中启用实验性的 ES 模块支持。
【Enable experimental ES Module support in the node:vm module.】
--experimental-wasi-unstable-preview1#>
启用实验性 WebAssembly 系统接口 (WASI) 支持。
【Enable experimental WebAssembly System Interface (WASI) support.】
--experimental-wasm-modules#>
启用实验性 WebAssembly 模块支持。
【Enable experimental WebAssembly module support.】
--force-context-aware#>
禁用加载非 上下文感知 的本地插件。
【Disable loading native addons that are not context-aware.】
--force-fips#>
在启动时强制使用 FIPS 兼容的加密。(无法从脚本代码中禁用。)
(与 --enable-fips 的要求相同。)
【Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)
(Same requirements as --enable-fips.)】
--frozen-intrinsics#>
启用实验性的冻结内置对象,如 Array 和 Object。
【Enable experimental frozen intrinsics like Array and Object.】
仅支持根上下文。无法保证 globalThis.Array 确实是默认的内在引用。在此标志下代码可能会出错。
【Only the root context is supported. There is no guarantee that
globalThis.Array is indeed the default intrinsic reference. Code may break
under this flag.】
为了允许添加 polyfill,--require 会在冻结内建对象之前运行。
【To allow polyfills to be added, --require runs before freezing intrinsics.】
--force-node-api-uncaught-exceptions-policy#>
在 Node-API 异步回调上强制触发 uncaughtException 事件。
【Enforces uncaughtException event on Node-API asynchronous callbacks.】
为了防止现有的插件导致进程崩溃,该标志默认未启用。将来,该标志将默认启用,以强制执行正确的行为。
【To prevent from an existing add-on from crashing the process, this flag is not enabled by default. In the future, this flag will be enabled by default to enforce the correct behavior.】
--heapsnapshot-near-heap-limit=max_count#>
当 V8 堆使用量接近堆限制时,将 V8 堆快照写入磁盘。count 应该是一个非负整数(在这种情况下,Node.js 不会将超过 max_count 个快照写入磁盘)。
【Writes a V8 heap snapshot to disk when the V8 heap usage is approaching the
heap limit. count should be a non-negative integer (in which case
Node.js will write no more than max_count snapshots to disk).】
在生成快照时,可能会触发垃圾回收,从而降低堆的使用量。因此,在 Node.js 实例最终耗尽内存之前,可能会将多个快照写入磁盘。这些堆快照可以进行比较,以确定在连续快照拍摄期间正在分配哪些对象。不能保证 Node.js 会正好将 max_count 个快照写入磁盘,但它会尽力在 Node.js 实例耗尽内存之前生成至少一个、最多 max_count 个快照,当 max_count 大于 0 时。
【When generating snapshots, garbage collection may be triggered and bring
the heap usage down. Therefore multiple snapshots may be written to disk
before the Node.js instance finally runs out of memory. These heap snapshots
can be compared to determine what objects are being allocated during the
time consecutive snapshots are taken. It's not guaranteed that Node.js will
write exactly max_count snapshots to disk, but it will try
its best to generate at least one and up to max_count snapshots before the
Node.js instance runs out of memory when max_count is greater than 0.】
生成 V8 快照需要时间和内存(包括 V8 堆管理的内存以及 V8 堆之外的本地内存)。堆越大,需要的资源就越多。Node.js 会调整 V8 堆以适应额外的 V8 堆内存开销,并尽量避免耗尽进程可用的所有内存。当进程使用的内存超过系统认为合适的范围时,根据系统配置,进程可能会被系统突然终止。
【Generating V8 snapshots takes time and memory (both memory managed by the V8 heap and native memory outside the V8 heap). The bigger the heap is, the more resources it needs. Node.js will adjust the V8 heap to accommodate the additional V8 heap memory overhead, and try its best to avoid using up all the memory available to the process. When the process uses more memory than the system deems appropriate, the process may be terminated abruptly by the system, depending on the system configuration.】
$ node --max-old-space-size=100 --heapsnapshot-near-heap-limit=3 index.js
Wrote snapshot to Heap.20200430.100036.49580.0.001.heapsnapshot
Wrote snapshot to Heap.20200430.100037.49580.0.002.heapsnapshot
Wrote snapshot to Heap.20200430.100038.49580.0.003.heapsnapshot
<--- Last few GCs --->
[49580:0x110000000] 4826 毫秒:标记-清除 130.6 (147.8) -> 130.5 (147.8) MB,27.4 / 0.0 毫秒(平均 mu = 0.126,当前 mu = 0.034)分配失败,清理可能不成功
[49580:0x110000000] 4845 毫秒:标记-清除 130.6 (147.8) -> 130.6 (147.8) MB,18.8 / 0.0 毫秒(平均 mu = 0.088,当前 mu = 0.031)分配失败,清理可能不成功
<--- JS stacktrace --->
致命错误:在堆边界附近的标记压缩无效,分配失败 - JavaScript 堆内存不足
....
【FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
....】
--heapsnapshot-signal=signal#>
启用一个信号处理程序,当收到指定信号时,使 Node.js 进程写入堆转储。signal 必须是有效的信号名称。默认情况下为禁用。
【Enables a signal handler that causes the Node.js process to write a heap dump
when the specified signal is received. signal must be a valid signal name.
Disabled by default.】
$ node --heapsnapshot-signal=SIGUSR2 index.js &
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
node 1 5.5 6.1 787252 247004 ? Ssl 16:43 0:02 node --heapsnapshot-signal=SIGUSR2 index.js
$ kill -USR2 1
$ ls
Heap.20190718.133405.15554.0.001.heapsnapshot
--heap-prof#>
在启动时启动 V8 堆分析器,并在退出前将堆分析结果写入磁盘。
【Starts the V8 heap profiler on start up, and writes the heap profile to disk before exit.】
如果未指定 --heap-prof-dir,生成的配置文件将放置在当前工作目录中。
【If --heap-prof-dir is not specified, the generated profile is placed
in the current working directory.】
如果未指定 --heap-prof-name,生成的配置文件将被命名为 Heap.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.heapprofile。
【If --heap-prof-name is not specified, the generated profile is
named Heap.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.heapprofile.】
$ node --heap-prof index.js
$ ls *.heapprofile
Heap.20190409.202950.15293.0.001.heapprofile
--heap-prof-dir#>
指定由 --heap-prof 生成的堆分析文件将被放置的目录。
【Specify the directory where the heap profiles generated by --heap-prof will
be placed.】
默认值由 --diagnostic-dir 命令行选项控制。
【The default value is controlled by the
--diagnostic-dir command-line option.】
--heap-prof-interval#>
指定生成堆配置文件的平均采样间隔(字节) 由“--堆-教授”编写。默认是512 * 1024字节。
【Specify the average sampling interval in bytes for the heap profiles generated
by --heap-prof. The default is 512 * 1024 bytes.】
--heap-prof-name#>
指定由 --heap-prof 生成的堆分析文件的文件名。
【Specify the file name of the heap profile generated by --heap-prof.】
--icu-data-dir=file#>
指定 ICU 数据加载路径。(会覆盖 NODE_ICU_DATA。)
【Specify ICU data load path. (Overrides NODE_ICU_DATA.)】
--input-type=type#>
这会配置 Node.js 将字符串输入解释为 CommonJS 或 ES 模块。字符串输入可以通过 --eval、--print 或 STDIN 提供。
【This configures Node.js to interpret string input as CommonJS or as an ES
module. String input is input via --eval, --print, or STDIN.】
有效值为 "commonjs" 和 "module"。默认值为 "commonjs"。
【Valid values are "commonjs" and "module". The default is "commonjs".】
REPL 不支持此选项。
【The REPL does not support this option.】
--inspect-brk[=[host:]port]#>
在 host:port 上启用检查器,并在用户脚本开始处暂停。默认的 host:port 是 127.0.0.1:9229。
【Activate inspector on host:port and break at start of user script.
Default host:port is 127.0.0.1:9229.】
--inspect-port=[host:]port#>
设置在激活调试器时使用的 host:port。在通过发送 SIGUSR1 信号激活调试器时非常有用。
【Set the host:port to be used when the inspector is activated.
Useful when activating the inspector by sending the SIGUSR1 signal.】
默认主机是 127.0.0.1。
【Default host is 127.0.0.1.】
请参见下面关于 host 参数使用的 安全警告。
【See the security warning below regarding the host
parameter usage.】
--inspect[=[host:]port]#>
在 host:port 上激活检查器。默认值是 127.0.0.1:9229。
【Activate inspector on host:port. Default is 127.0.0.1:9229.】
V8 检查器集成允许诸如 Chrome DevTools 和 IDE 等工具调试和分析 Node.js 实例。工具通过 TCP 端口附加到 Node.js 实例,并使用 Chrome 开发者工具协议 进行通信。
【V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug and profile Node.js instances. The tools attach to Node.js instances via a tcp port and communicate using the Chrome DevTools Protocol.】
警告:将检查器绑定到公共 IP:端口组合是不安全的#>
【Warning: binding inspector to a public IP:port combination is insecure】
将检查器绑定到带有开放端口的公共 IP(包括 0.0.0.0)是不安全的,因为它允许外部主机连接到检查器并执行 远程代码执行 攻击。
【Binding the inspector to a public IP (including 0.0.0.0) with an open port is
insecure, as it allows external hosts to connect to the inspector and perform
a remote code execution attack.】
如果指定主机,请确保:
【If specifying a host, make sure that either:】
- 该主机无法从公共网络访问。
- 防火墙阻止端口上的不受欢迎连接。
更具体地说,如果端口(默认是 9229)没有防火墙保护,--inspect=0.0.0.0 是不安全的。
有关更多信息,请参阅 调试的安全影响 部分。
【See the debugging security implications section for more information.】
--inspect-publish-uid=stderr,http#>
指定检查器网络套接字网址的暴露方式。
【Specify ways of the inspector web socket url exposure.】
默认情况下,检查器的 websocket URL 可以在标准错误输出(stderr)中找到,也可以通过 http://host:port/json/list 的 /json/list 端点访问。
【By default inspector websocket url is available in stderr and under /json/list
endpoint on http://host:port/json/list.】
--insecure-http-parser#>
使用一个不安全的 HTTP 解析器,它可以接受无效的 HTTP 头。这可能允许与不符合规范的 HTTP 实现进行互操作。它也可能允许请求走私和其他依赖于接受无效头的 HTTP 攻击。请避免使用此选项。
【Use an insecure HTTP parser that accepts invalid HTTP headers. This may allow interoperability with non-conformant HTTP implementations. It may also allow request smuggling and other HTTP attacks that rely on invalid headers being accepted. Avoid using this option.】
--jitless#>
禁用 可执行内存的运行时分配。这在某些平台上可能出于安全原因是必需的。在其他平台上,它也可以减少攻击面,但性能影响可能很严重。
【Disable runtime allocation of executable memory. This may be required on some platforms for security reasons. It can also reduce attack surface on other platforms, but the performance impact may be severe.】
此标志继承自 V8,并可能在上游发生变化。它可能会在非语义化版本的重大更新中消失。
【This flag is inherited from V8 and is subject to change upstream. It may disappear in a non-semver-major release.】
--max-http-header-size=size#>
指定 HTTP 请求头的最大大小(以字节为单位)。默认值为 16 KiB。
【Specify the maximum size, in bytes, of HTTP headers. Defaults to 16 KiB.】
--napi-modules#>
此选项无任何操作。它保留是为了兼容性。
【This option is a no-op. It is kept for compatibility.】
--no-addons#>
禁用 node-addons 导出条件,同时禁用加载本地插件。当指定 --no-addons 时,调用 process.dlopen 或加载本地 C++ 插件将会失败并抛出异常。
【Disable the node-addons exports condition as well as disable loading
native addons. When --no-addons is specified, calling process.dlopen or
requiring a native C++ addon will fail and throw an exception.】
--no-deprecation#>
静默弃用警告。
【Silence deprecation warnings.】
--no-force-async-hooks-checks#>
禁用 async_hooks 的运行时检查。当启用 async_hooks 时,这些检查仍会动态启用。
【Disables runtime checks for async_hooks. These will still be enabled
dynamically when async_hooks is enabled.】
--no-global-search-paths#>
不要从全局路径如 $HOME/.node_modules 和 $NODE_PATH 搜索模块。
【Do not search modules from global paths like $HOME/.node_modules and
$NODE_PATH.】
--no-warnings#>
静默所有进程警告(包括弃用的)。
【Silence all process warnings (including deprecations).】
--node-memory-debug#>
启用针对 Node.js 内部的额外内存泄漏调试检查。这通常只对调试 Node.js 本身的开发者有用。
【Enable extra debug checks for memory leaks in Node.js internals. This is usually only useful for developers debugging Node.js itself.】
--openssl-config=file#>
在启动时加载 OpenSSL 配置文件。除其他用途外,如果 Node.js 是针对启用 FIPS 的 OpenSSL 构建的,这可以用于启用符合 FIPS 的加密。
【Load an OpenSSL configuration file on startup. Among other uses, this can be used to enable FIPS-compliant crypto if Node.js is built against FIPS-enabled OpenSSL.】
--openssl-shared-config#>
启用 OpenSSL 默认配置部分 openssl_conf,以便从 OpenSSL 配置文件中读取。默认的配置文件名为 openssl.cnf,但可以通过环境变量 OPENSSL_CONF 或命令行选项 --openssl-config 更改。默认 OpenSSL 配置文件的位置取决于 OpenSSL 如何与 Node.js 进行链接。共享 OpenSSL 配置可能会带来不希望的影响,建议使用专用于 Node.js 的配置部分 nodejs_conf,当不使用此选项时,该部分为默认配置。
【Enable OpenSSL default configuration section, openssl_conf to be read from
the OpenSSL configuration file. The default configuration file is named
openssl.cnf but this can be changed using the environment variable
OPENSSL_CONF, or by using the command line option --openssl-config.
The location of the default OpenSSL configuration file depends on how OpenSSL
is being linked to Node.js. Sharing the OpenSSL configuration may have unwanted
implications and it is recommended to use a configuration section specific to
Node.js which is nodejs_conf and is default when this option is not used.】
--openssl-legacy-provider#>
在动态链接到 OpenSSL 3.x 时启用 OpenSSL 3.0 传统提供程序。更多信息请参见 OSSL_提供者-传统。
【Enable OpenSSL 3.0 legacy provider when dynamically linking to OpenSSL 3.x. For more information please see OSSL_PROVIDER-legacy.】
--pending-deprecation#>
触发挂起的弃用警告。
【Emit pending deprecation warnings.】
待弃用通常与运行时弃用完全相同,其显著区别在于,默认情况下它们是关闭的,并且不会被触发,除非设置了 --pending-deprecation 命令行标志或 NODE_PENDING_DEPRECATION=1 环境变量。待弃用用于提供一种选择性的“提前警告”机制,开发者可以利用它来检测已弃用的 API 使用情况。
【Pending deprecations are generally identical to a runtime deprecation with the
notable exception that they are turned off by default and will not be emitted
unless either the --pending-deprecation command-line flag, or the
NODE_PENDING_DEPRECATION=1 environment variable, is set. Pending deprecations
are used to provide a kind of selective "early warning" mechanism that
developers may leverage to detect deprecated API usage.】
--policy-integrity=sri#>
指示 Node.js 在运行任何代码之前,如果策略没有指定的完整性,则报错。它期望将 子资源完整性 字符串作为参数。
【Instructs Node.js to error prior to running any code if the policy does not have the specified integrity. It expects a Subresource Integrity string as a parameter.】
--preserve-symlinks#>
指示模块加载器在解析和缓存模块时保留符号链接。
【Instructs the module loader to preserve symbolic links when resolving and caching modules.】
默认情况下,当 Node.js 从符号链接到不同磁盘位置的路径加载模块时,Node.js 会取消引用该链接,并使用模块的实际磁盘“真实路径”作为标识符,以及作为定位其他依赖模块的根路径。在大多数情况下,这种默认行为是可接受的。然而,当使用符号链接的对等依赖时,如下面的示例所示,如果 moduleA 尝试将 moduleB 作为对等依赖来 require,默认行为会导致抛出异常:
【By default, when Node.js loads a module from a path that is symbolically linked
to a different on-disk location, Node.js will dereference the link and use the
actual on-disk "real path" of the module as both an identifier and as a root
path to locate other dependency modules. In most cases, this default behavior
is acceptable. However, when using symbolically linked peer dependencies, as
illustrated in the example below, the default behavior causes an exception to
be thrown if moduleA attempts to require moduleB as a peer dependency:】
{appDir}
├── app
│ ├── index.js
│ └── node_modules
│ ├── moduleA -> {appDir}/moduleA
│ └── moduleB
│ ├── index.js
│ └── package.json
└── moduleA
├── index.js
└── package.json
--preserve-symlinks 命令行标志指示 Node.js 使用模块的符号链接路径而不是真实路径,从而允许找到符号链接的同级依赖。
【The --preserve-symlinks command-line flag instructs Node.js to use the
symlink path for modules as opposed to the real path, allowing symbolically
linked peer dependencies to be found.】
请注意,使用 --preserve-symlinks 可能会有其他副作用。具体来说,如果符号链接的 原生 模块从依赖树中的多个位置链接,可能会加载失败(Node.js 会将它们视为两个独立的模块,并尝试多次加载该模块,从而导致抛出异常)。
【Note, however, that using --preserve-symlinks can have other side effects.
Specifically, symbolically linked native modules can fail to load if those
are linked from more than one location in the dependency tree (Node.js would
see those as two separate modules and would attempt to load the module multiple
times, causing an exception to be thrown).】
--preserve-symlinks 标志不适用于主模块,这使得 node --preserve-symlinks node_module/.bin/<foo> 能够工作。要在主模块上应用相同的行为,还需要使用 --preserve-symlinks-main。
【The --preserve-symlinks flag does not apply to the main module, which allows
node --preserve-symlinks node_module/.bin/<foo> to work. To apply the same
behavior for the main module, also use --preserve-symlinks-main.】
--preserve-symlinks-main#>
指示模块加载器在解析和缓存主模块(require.main)时保留符号链接。
【Instructs the module loader to preserve symbolic links when resolving and
caching the main module (require.main).】
这个标志存在是为了让主模块可以选择采用 --preserve-symlinks 对所有其他导入所提供的相同行为;不过,它们是单独的标志,以便向旧版本的 Node.js 保持向后兼容。
【This flag exists so that the main module can be opted-in to the same behavior
that --preserve-symlinks gives to all other imports; they are separate flags,
however, for backward compatibility with older Node.js versions.】
--preserve-symlinks-main 并不意味着 --preserve-symlinks;当不希望在解析相对路径之前跟随符号链接时,应将 --preserve-symlinks-main 与 --preserve-symlinks 一起使用。
有关更多信息,请参见 --preserve-symlinks。
【See --preserve-symlinks for more information.】
--prof#>
生成 V8 分析器输出。
【Generate V8 profiler output.】
--prof-process#>
处理使用 V8 选项 --prof 生成的 V8 分析器输出。
【Process V8 profiler output generated using the V8 option --prof.】
--redirect-warnings=file#>
将进程警告写入指定文件,而不是打印到标准错误。如果文件不存在,将创建该文件;如果文件已存在,将在其末尾追加内容。如果在尝试将警告写入文件时发生错误,警告将改为写入标准错误。
【Write process warnings to the given file instead of printing to stderr. The file will be created if it does not exist, and will be appended to if it does. If an error occurs while attempting to write the warning to the file, the warning will be written to stderr instead.】
file 名称可以是绝对路径。如果不是,文件将被写入的默认目录由 --diagnostic-dir 命令行选项控制。
【The file name may be an absolute path. If it is not, the default directory it
will be written to is controlled by the
--diagnostic-dir command-line option.】
--report-compact#>
以紧凑格式编写报告,单行 JSON,比为人类阅读设计的默认多行格式更易被日志处理系统消费。
【Write reports in a compact format, single-line JSON, more easily consumable by log processing systems than the default multi-line format designed for human consumption.】
--report-dir=目录,report-directory=目录#>
【--report-dir=directory, report-directory=directory】
生成报告的位置。
【Location at which the report will be generated.】
--report-filename=filename#>
将写入报告的文件的名称。
【Name of the file to which the report will be written.】
如果文件名设置为 'stdout' 或 'stderr',报告将分别写入进程的标准输出或标准错误。
【If the filename is set to 'stdout' or 'stderr', the report is written to
the stdout or stderr of the process respectively.】
--report-on-fatalerror#>
启用在致命错误(Node.js 运行时的内部错误,例如内存耗尽)发生时触发报告的功能,这些错误会导致应用终止。可用于检查各种诊断数据元素,如堆、堆栈、事件循环状态、资源消耗等,以分析致命错误的原因。
【Enables the report to be triggered on fatal errors (internal errors within the Node.js runtime such as out of memory) that lead to termination of the application. Useful to inspect various diagnostic data elements such as heap, stack, event loop state, resource consumption etc. to reason about the fatal error.】
--report-on-signal#>
在接收到发送到正在运行的 Node.js 进程的指定(或预定义)信号时,启用生成报告。触发报告的信号通过 --report-signal 指定。
【Enables report to be generated upon receiving the specified (or predefined)
signal to the running Node.js process. The signal to trigger the report is
specified through --report-signal.】
--report-signal=signal#>
设置或重置报告生成的信号(Windows 不支持)。
默认信号是 SIGUSR2。
【Sets or resets the signal for report generation (not supported on Windows).
Default signal is SIGUSR2.】
--report-uncaught-exception#>
当进程因未捕获的异常退出时,允许生成报告。在结合本地堆栈和其他运行时环境数据检查 JavaScript 堆栈时非常有用。
【Enables report to be generated when the process exits due to an uncaught exception. Useful when inspecting the JavaScript stack in conjunction with native stack and other runtime environment data.】
--secure-heap=n#>
初始化一个大小为 n 字节的 OpenSSL 安全堆。初始化后,安全堆会在 OpenSSL 中的某些分配类型中使用,例如在密钥生成和其他操作期间。这非常有用,例如可以防止由于指针越界或下溢导致的敏感信息泄露。
【Initializes an OpenSSL secure heap of n bytes. When initialized, the
secure heap is used for selected types of allocations within OpenSSL
during key generation and other operations. This is useful, for instance,
to prevent sensitive information from leaking due to pointer overruns
or underruns.】
安全堆的大小是固定的,无法在运行时调整,因此,如果使用它,选择一个足够大的堆以覆盖所有应用的使用非常重要。
【The secure heap is a fixed size and cannot be resized at runtime so, if used, it is important to select a large enough heap to cover all application uses.】
指定的堆大小必须是二的幂。小于 2 的任意值将禁用安全堆。
【The heap size given must be a power of two. Any value less than 2 will disable the secure heap.】
默认情况下禁用安全堆。
【The secure heap is disabled by default.】
安全堆在 Windows 上不可用。
【The secure heap is not available on Windows.】
有关详细信息,请参见CRYPTO_secure_malloc_init。
【See CRYPTO_secure_malloc_init for more details.】
--secure-heap-min=n#>
在使用 --secure-heap 时,--secure-heap-min 参数指定从安全堆分配的最小值。最小值为 2。最大值为 --secure-heap 和 2147483647 中的较小者。指定的值必须是二的幂。
【When using --secure-heap, the --secure-heap-min flag specifies the
minimum allocation from the secure heap. The minimum value is 2.
The maximum value is the lesser of --secure-heap or 2147483647.
The value given must be a power of two.】
--test#>
启动 Node.js 命令行测试运行器。此标志不能与 --check、--eval、--interactive 或调试器一起使用。有关详细信息,请参阅 从命令行运行测试 文档。
【Starts the Node.js command line test runner. This flag cannot be combined with
--check, --eval, --interactive, or the inspector. See the documentation
on running tests from the command line for more details.】
--test-only#>
将测试运行器配置为仅执行设置了 only 选项的顶层测试。
【Configures the test runner to only execute top level tests that have the only
option set.】
--throw-deprecation#>
为弃用抛出错误。
【Throw errors for deprecations.】
--title=title#>
在启动时设置 process.title。
【Set process.title on startup.】
--tls-cipher-list=list#>
指定一个备用的默认 TLS 密码套件列表。需要 Node.js 在构建时启用加密支持(默认)。
【Specify an alternative default TLS cipher list. Requires Node.js to be built with crypto support (default).】
--tls-keylog=file#>
将 TLS 密钥材料记录到文件中。密钥材料采用 NSS SSLKEYLOGFILE 格式,可被软件(如 Wireshark)用来解密 TLS 流量。
【Log TLS key material to a file. The key material is in NSS SSLKEYLOGFILE
format and can be used by software (such as Wireshark) to decrypt the TLS
traffic.】
--tls-max-v1.2#>
将 tls.DEFAULT_MAX_VERSION 设置为 'TLSv1.2'。用于禁用对 TLSv1.3 的支持。
【Set tls.DEFAULT_MAX_VERSION to 'TLSv1.2'. Use to disable support for
TLSv1.3.】
--tls-max-v1.3#>
将默认 tls.DEFAULT_MAX_VERSION 设置为 'TLSv1.3'。用于启用对 TLSv1.3 的支持。
【Set default tls.DEFAULT_MAX_VERSION to 'TLSv1.3'. Use to enable support
for TLSv1.3.】
--tls-min-v1.0#>
将默认 tls.DEFAULT_MIN_VERSION 设置为 'TLSv1'。用于与旧版 TLS 客户端或服务器兼容。
【Set default tls.DEFAULT_MIN_VERSION to 'TLSv1'. Use for compatibility with
old TLS clients or servers.】
--tls-min-v1.1#>
将默认 tls.DEFAULT_MIN_VERSION 设置为 'TLSv1.1'。用于与旧版 TLS 客户端或服务器的兼容性。
【Set default tls.DEFAULT_MIN_VERSION to 'TLSv1.1'. Use for compatibility
with old TLS clients or servers.】
--tls-min-v1.2#>
将默认 tls.DEFAULT_MIN_VERSION 设置为 'TLSv1.2'。这是 12.x 及更高版本的默认设置,但该选项可用于与较旧的 Node.js 版本兼容。
【Set default tls.DEFAULT_MIN_VERSION to 'TLSv1.2'. This is the default for
12.x and later, but the option is supported for compatibility with older Node.js
versions.】
--tls-min-v1.3#>
将默认 tls.DEFAULT_MIN_VERSION 设置为 'TLSv1.3'。用于禁用对 TLSv1.2 的支持,因为它不如 TLSv1.3 安全。
【Set default tls.DEFAULT_MIN_VERSION to 'TLSv1.3'. Use to disable support
for TLSv1.2, which is not as secure as TLSv1.3.】
--trace-atomics-wait#>
将对 Atomics.wait() 的调用简要摘要打印到标准错误。输出可能如下所示:
【Print short summaries of calls to Atomics.wait() to stderr.
The output could look like this:】
(node:15701) [Thread 0] Atomics.wait(<address> + 0, 1, inf) started
(node:15701) [Thread 0] Atomics.wait(<address> + 0, 1, inf) did not wait because the values mismatched
(node:15701) [Thread 0] Atomics.wait(<address> + 0, 0, 10) started
(node:15701) [Thread 0] Atomics.wait(<address> + 0, 0, 10) timed out
(node:15701) [Thread 0] Atomics.wait(<address> + 4, 0, inf) started
(node:15701) [Thread 1] Atomics.wait(<address> + 4, -1, inf) started
(node:15701) [Thread 0] Atomics.wait(<address> + 4, 0, inf) was woken up by another thread
(node:15701) [Thread 1] Atomics.wait(<address> + 4, -1, inf) was woken up by another thread
这里的字段对应于:
【The fields here correspond to:】
- 由
worker_threads.threadId提供的线程 ID - 相关
SharedArrayBuffer的基地址,以及对应传递给Atomics.wait()的索引的字节偏移 - 传递给
Atomics.wait()的期望值 - 传递给
Atomics.wait的超时
--trace-deprecation#>
打印弃用的堆栈跟踪。
【Print stack traces for deprecations.】
--trace-event-categories#>
使用 --trace-events-enabled 启用跟踪事件追踪时,应该被追踪的类别的逗号分隔列表。
【A comma separated list of categories that should be traced when trace event
tracing is enabled using --trace-events-enabled.】
--trace-event-file-pattern#>
指定跟踪事件数据文件路径的模板字符串,它支持 ${rotation} 和 ${pid}。
【Template string specifying the filepath for the trace event data, it
supports ${rotation} and ${pid}.】
--trace-events-enabled#>
启用跟踪事件跟踪信息的收集。
【Enables the collection of trace event tracing information.】
--trace-exit#>
每当主动退出环境时,即调用 process.exit(),都会打印堆栈跟踪。
【Prints a stack trace whenever an environment is exited proactively,
i.e. invoking process.exit().】
--trace-sigint#>
在 SIGINT 上打印堆栈跟踪。
【Prints a stack trace on SIGINT.】
--trace-sync-io#>
在事件循环的第一次循环之后检测到同步 I/O 时打印堆栈跟踪。
【Prints a stack trace whenever synchronous I/O is detected after the first turn of the event loop.】
--trace-tls#>
将 TLS 数据包跟踪信息打印到 stderr。这可用于调试 TLS 连接问题。
【Prints TLS packet trace information to stderr. This can be used to debug TLS
connection problems.】
--trace-uncaught#>
打印未捕获异常的堆栈跟踪;通常会打印与创建 Error 相关的堆栈跟踪,而此选项会让 Node.js 还打印与抛出值相关的堆栈跟踪(抛出的值不必是 Error 实例)。
【Print stack traces for uncaught exceptions; usually, the stack trace associated
with the creation of an Error is printed, whereas this makes Node.js also
print the stack trace associated with throwing the value (which does not need
to be an Error instance).】
启用此选项可能会对垃圾回收行为产生负面影响。
【Enabling this option may affect garbage collection behavior negatively.】
--trace-warnings#>
打印进程警告的堆栈跟踪(包括弃用)。
【Print stack traces for process warnings (including deprecations).】
--track-heap-objects#>
跟踪堆快照的堆对象分配。
【Track heap object allocations for heap snapshots.】
--unhandled-rejections=mode#>
使用此标志可以更改在发生未处理的拒绝时应发生的操作。可以选择以下模式之一:
【Using this flag allows to change what should happen when an unhandled rejection occurs. One of the following modes can be chosen:】
throw:发出unhandledRejection。如果未设置此钩子,则将未处理的拒绝作为未捕获异常抛出。这是默认行为。strict:将未处理的拒绝作为未捕获异常抛出。如果异常被处理,将触发unhandledRejection。warn:始终触发警告,无论unhandledRejection钩子是否设置,但不要打印弃用警告。warn-with-error-code:发出unhandledRejection。如果未设置此钩子,则触发警告,并将进程退出码设置为 1。none:静音所有警告。
如果在命令行入口点的 ES 模块静态加载阶段发生拒绝,它将始终将其作为未捕获的异常引发。
【If a rejection happens during the command line entry point's ES module static loading phase, it will always raise it as an uncaught exception.】
--use-bundled-ca,--use-openssl-ca#>
【--use-bundled-ca, --use-openssl-ca】
使用当前 Node.js 版本提供的打包 Mozilla CA 存储,或使用 OpenSSL 的默认 CA 存储。默认存储可在构建时选择。
【Use bundled Mozilla CA store as supplied by current Node.js version or use OpenSSL's default CA store. The default store is selectable at build-time.】
由 Node.js 提供的打包 CA 证书库是 Mozilla CA 证书库在发布时的快照。在所有支持的平台上都是相同的。
【The bundled CA store, as supplied by Node.js, is a snapshot of Mozilla CA store that is fixed at release time. It is identical on all supported platforms.】
使用 OpenSSL 存储允许对存储进行外部修改。对于大多数 Linux 和 BSD 发行版,该存储由发行版维护者和系统管理员维护。OpenSSL CA 存储的位置取决于 OpenSSL 库的配置,但可以在运行时使用环境变量进行更改。
【Using OpenSSL store allows for external modifications of the store. For most Linux and BSD distributions, this store is maintained by the distribution maintainers and system administrators. OpenSSL CA store location is dependent on configuration of the OpenSSL library but this can be altered at runtime using environment variables.】
请参见 SSL_CERT_DIR 和 SSL_CERT_FILE。
【See SSL_CERT_DIR and SSL_CERT_FILE.】
--use-largepages=mode#>
在启动时将 Node.js 静态代码重新映射到大内存页。如果目标系统支持,这将导致 Node.js 静态代码被移动到 2 MiB 页而不是 4 KiB 页上。
【Re-map the Node.js static code to large memory pages at startup. If supported on the target system, this will cause the Node.js static code to be moved onto 2 MiB pages instead of 4 KiB pages.】
mode 的以下值是有效的:
【The following values are valid for mode:】
off:不会尝试映射。这是默认设置。on:如果操作系统支持,将尝试进行映射。映射失败将被忽略,并且消息会打印到标准错误输出。silent:如果操作系统支持,将尝试映射。映射失败将被忽略,不会报告。
--v8-options#>
打印 V8 命令行选项。
【Print V8 command-line options.】
--v8-pool-size=num#>
设置 V8 的线程池大小,用于分配后台作业。
【Set V8's thread pool size which will be used to allocate background jobs.】
如果设置为 0,则 V8 将根据在线处理器的数量选择合适的线程池大小。
【If set to 0 then V8 will choose an appropriate size of the thread pool based
on the number of online processors.】
如果提供的值大于 V8 的最大值,则将选择最大值。
【If the value provided is larger than V8's maximum, then the largest value will be chosen.】
--watch#>
以监视模式启动 Node.js。
在监视模式下,被监视的文件发生更改会导致 Node.js 进程重启。
默认情况下,监视模式会监视入口点以及所有所需或导入的模块。
使用 --watch-path 来指定要监视的路径。
【Starts Node.js in watch mode.
When in watch mode, changes in the watched files cause the Node.js process to
restart.
By default, watch mode will watch the entry point
and any required or imported module.
Use --watch-path to specify what paths to watch.】
此标志不能与 --check、--eval、--interactive 或 REPL 一起使用。
【This flag cannot be combined with
--check, --eval, --interactive, or the REPL.】
$ node --watch index.js
--watch-path#>
以监视模式启动 Node.js,并指定要监视的路径。 在监视模式下,被监视路径的更改会导致 Node.js 进程重新启动。 这将关闭对所需或导入模块的监视,即使与 --watch 结合使用也一样。
【Starts Node.js in watch mode and specifies what paths to watch.
When in watch mode, changes in the watched paths cause the Node.js process to
restart.
This will turn off watching of required or imported modules, even when used in
combination with --watch.】
此标志不能与 --check、--eval、--interactive 或 REPL 一起使用。
【This flag cannot be combined with
--check, --eval, --interactive, or the REPL.】
$ node --watch-path=./src --watch-path=./tests index.js
此选项仅在 macOS 和 Windows 上受支持。
在不支持该选项的平台上使用时,将抛出 ERR_FEATURE_UNAVAILABLE_ON_PLATFORM 异常。
【This option is only supported on macOS and Windows.
An ERR_FEATURE_UNAVAILABLE_ON_PLATFORM exception will be thrown
when the option is used on a platform that does not support it.】
--zero-fill-buffers#>
自动将所有新分配的 Buffer 和 SlowBuffer 实例填充为零。
【Automatically zero-fills all newly allocated Buffer and SlowBuffer
instances.】
-c,--check#>
【-c, --check】
语法检查脚本而不执行。
【Syntax check the script without executing.】
-e,--eval "脚本"#>
【-e, --eval "script"】
将以下参数作为 JavaScript 进行评估。在 REPL 中预定义的模块也可以在 script 中使用。
【Evaluate the following argument as JavaScript. The modules which are
predefined in the REPL can also be used in script.】
在 Windows 上,使用 cmd.exe 时,单引号无法正确工作,因为它只识别双引号 " 作为引用。在 Powershell 或 Git bash 中,单引号 ' 和双引号 " 都可以使用。
【On Windows, using cmd.exe a single quote will not work correctly because it
only recognizes double " for quoting. In Powershell or Git bash, both '
and " are usable.】
-h,--help#>
【-h, --help】
打印节点命令行选项。该选项的输出不如本文档详细。
【Print node command-line options. The output of this option is less detailed than this document.】
-i,--interactive#>
【-i, --interactive】
即使标准输入似乎不是终端,也会打开交互式解释器。
【Opens the REPL even if stdin does not appear to be a terminal.】
-p,--print "script"#>
【-p, --print "script"】
与 -e 相同,但会打印结果。
【Identical to -e but prints the result.】
-r,--require 模块#>
【-r, --require module】
在启动时预加载指定的模块。
【Preload the specified module at startup.】
遵循 require() 的模块解析规则。module 可以是文件路径,也可以是节点模块名称。
【Follows require()'s module resolution
rules. module may be either a path to a file, or a node module name.】
仅支持 CommonJS 模块。尝试使用 --require 预加载 ES6 模块会报错。
【Only CommonJS modules are supported. Attempting to preload a
ES6 Module using --require will fail with an error.】
-v,--version#>
【-v, --version】
打印 node 的版本。
【Print node's version.】
环境变量#>
【Environment variables】
FORCE_COLOR=[1, 2, 3]#>
FORCE_COLOR 环境变量用于启用 ANSI 彩色输出。其值可以是:
【The FORCE_COLOR environment variable is used to
enable ANSI colorized output. The value may be:】
1、true或空字符串''表示支持 16 色。2表示支持 256 色,或者3表示支持 1600 万色。
当使用 FORCE_COLOR 并设置为支持的值时,NO_COLOR 和 NODE_DISABLE_COLORS 环境变量将被忽略。
【When FORCE_COLOR is used and set to a supported value, both the NO_COLOR,
and NODE_DISABLE_COLORS environment variables are ignored.】
任何其他值都会导致彩色输出被禁用。
【Any other value will result in colorized output being disabled.】
NODE_DEBUG=module[,…]#>
',' 分隔的核心模块列表,这些模块应该打印调试信息。
NODE_DEBUG_NATIVE=module[,…]#>
应打印调试信息的核心 C++ 模块的,分隔列表。
NODE_DISABLE_COLORS=1#>
当设置时,颜色将不会在交互式解释器中使用。
【When set, colors will not be used in the REPL.】
NODE_EXTRA_CA_CERTS=file#>
设置后,知名的“根”证书颁发机构(如 VeriSign)将会使用 file 中的额外证书进行扩展。该文件应包含一个或多个 PEM 格式的受信任证书。如果文件缺失或格式错误,将会(仅一次)发出 process.emitWarning() 消息,但其他任何错误将被忽略。
【When set, the well known "root" CAs (like VeriSign) will be extended with the
extra certificates in file. The file should consist of one or more trusted
certificates in PEM format. A message will be emitted (once) with
process.emitWarning() if the file is missing or
malformed, but any errors are otherwise ignored.】
当为 TLS 或 HTTPS 客户端或服务器显式指定 ca 选项属性时,既不会使用知名证书,也不会使用额外证书。
【Neither the well known nor extra certificates are used when the ca
options property is explicitly specified for a TLS or HTTPS client or server.】
当 node 以 setuid root 运行或设置了 Linux 文件能力时,此环境变量将被忽略。
【This environment variable is ignored when node runs as setuid root or
has Linux file capabilities set.】
NODE_EXTRA_CA_CERTS 环境变量只在 Node.js 进程首次启动时读取。运行时使用 process.env.NODE_EXTRA_CA_CERTS 更改其值不会影响当前进程。
【The NODE_EXTRA_CA_CERTS environment variable is only read when the Node.js
process is first launched. Changing the value at runtime using
process.env.NODE_EXTRA_CA_CERTS has no effect on the current process.】
NODE_ICU_DATA=file#>
ICU(Intl 对象)数据的数据路径。在使用 small-icu 支持编译时,将扩展已链接的数据。
【Data path for ICU (Intl object) data. Will extend linked-in data when compiled
with small-icu support.】
NODE_NO_WARNINGS=1#>
设置为 1 时,进程警告将被静音。
【When set to 1, process warnings are silenced.】
NODE_OPTIONS=options...#>
以空格分隔的命令行选项列表。options... 会在命令行选项之前被解析,因此命令行选项将会覆盖或在 options... 的基础上叠加。如果使用了环境中不允许的选项,例如 -p 或脚本文件,Node.js 将会报错并退出。
【A space-separated list of command-line options. options... are interpreted
before command-line options, so command-line options will override or
compound after anything in options.... Node.js will exit with an error if
an option that is not allowed in the environment is used, such as -p or a
script file.】
如果选项值包含空格,则可以使用双引号转义:
【If an option value contains a space, it can be escaped using double quotes:】
NODE_OPTIONS='--require "./my path/file.js"'
作为命令行选项传递的单例标志将覆盖传入 NODE_OPTIONS 的相同标志:
【A singleton flag passed as a command-line option will override the same flag
passed into NODE_OPTIONS:】
# The inspector will be available on port 5555
NODE_OPTIONS='--inspect=localhost:4444' node --inspect=localhost:5555
可以多次传递的标志将被视为先传递其 NODE_OPTIONS 实例,然后再传递其命令行实例:
【A flag that can be passed multiple times will be treated as if its
NODE_OPTIONS instances were passed first, and then its command-line
instances afterwards:】
NODE_OPTIONS='--require "./a.js"' node --require "./b.js"
# is equivalent to:
node --require "./a.js" --require "./b.js"
允许的 Node.js 选项是:
【Node.js options that are allowed are:】
--conditions,-C--diagnostic-dir--disable-proto--dns-result-order--enable-fips--enable-source-maps--experimental-abortcontroller--experimental-fetch--experimental-global-customevent--experimental-global-webcrypto--experimental-import-meta-resolve--experimental-json-modules--experimental-loader--experimental-modules--experimental-network-imports--experimental-policy--experimental-specifier-resolution--experimental-top-level-await--experimental-vm-modules--experimental-wasi-unstable-preview1--experimental-wasm-modules--force-context-aware--force-fips--force-node-api-uncaught-exceptions-policy--frozen-intrinsics--heapsnapshot-near-heap-limit--heapsnapshot-signal--http-parser--icu-data-dir--input-type--insecure-http-parser--inspect-brk--inspect-port,--debug-port--inspect-publish-uid--inspect--max-http-header-size--napi-modules--no-addons--no-deprecation--no-experimental-repl-await--no-force-async-hooks-checks--no-global-search-paths--no-warnings--node-memory-debug--openssl-config--openssl-legacy-provider--openssl-shared-config--pending-deprecation--policy-integrity--preserve-symlinks-main--preserve-symlinks--prof-process--redirect-warnings--report-compact--report-dir,--report-directory--report-filename--report-on-fatalerror--report-on-signal--report-signal--report-uncaught-exception--require,-r--secure-heap-min--secure-heap--test-only--throw-deprecation--title--tls-cipher-list--tls-keylog--tls-max-v1.2--tls-max-v1.3--tls-min-v1.0--tls-min-v1.1--tls-min-v1.2--tls-min-v1.3--trace-atomics-wait--trace-deprecation--trace-event-categories--trace-event-file-pattern--trace-events-enabled--trace-exit--trace-sigint--trace-sync-io--trace-tls--trace-uncaught--trace-warnings--track-heap-objects--unhandled-rejections--use-bundled-ca--use-largepages--use-openssl-ca--v8-pool-size--watch-path--watch--zero-fill-buffers
允许的 V8 选项是:
【V8 options that are allowed are:】
--abort-on-uncaught-exception--disallow-code-generation-from-strings--huge-max-old-generation-size--interpreted-frames-native-stack--jitless--max-old-space-size--perf-basic-prof-only-functions--perf-basic-prof--perf-prof-unwinding-info--perf-prof--stack-trace-limit
--perf-basic-prof-only-functions、--perf-basic-prof、--perf-prof-unwinding-info 和 --perf-prof 仅在 Linux 上可用。
NODE_PATH=path[:…]#>
':' 分隔的目录列表,前缀到模块搜索路径。
在 Windows 上,这反而是一个用 ';' 分隔的列表。
【On Windows, this is a ';'-separated list instead.】
NODE_PENDING_DEPRECATION=1#>
设置为 1 时,会发出待定弃用警告。
【When set to 1, emit pending deprecation warnings.】
待弃用通常与运行时弃用完全相同,其显著区别在于,默认情况下它们是关闭的,并且不会被触发,除非设置了 --pending-deprecation 命令行标志或 NODE_PENDING_DEPRECATION=1 环境变量。待弃用用于提供一种选择性的“提前警告”机制,开发者可以利用它来检测已弃用的 API 使用情况。
【Pending deprecations are generally identical to a runtime deprecation with the
notable exception that they are turned off by default and will not be emitted
unless either the --pending-deprecation command-line flag, or the
NODE_PENDING_DEPRECATION=1 environment variable, is set. Pending deprecations
are used to provide a kind of selective "early warning" mechanism that
developers may leverage to detect deprecated API usage.】
NODE_PENDING_PIPE_INSTANCES=instances#>
设置管道服务器等待连接时的挂起管道实例句柄数量。此设置仅适用于 Windows。
【Set the number of pending pipe instance handles when the pipe server is waiting for connections. This setting applies to Windows only.】
NODE_PRESERVE_SYMLINKS=1#>
当设置为 1 时,指示模块加载器在解析和缓存模块时保留符号链接。
【When set to 1, instructs the module loader to preserve symbolic links when
resolving and caching modules.】
NODE_REDIRECT_WARNINGS=file#>
设置后,进程警告将输出到指定文件,而不是打印到标准错误。若文件不存在,将会创建该文件;若文件已存在,则会追加内容。如果在尝试将警告写入文件时发生错误,警告将改为写入标准错误。这相当于使用 --redirect-warnings=file 命令行选项。
【When set, process warnings will be emitted to the given file instead of
printing to stderr. The file will be created if it does not exist, and will be
appended to if it does. If an error occurs while attempting to write the
warning to the file, the warning will be written to stderr instead. This is
equivalent to using the --redirect-warnings=file command-line flag.】
NODE_REPL_HISTORY=file#>
用于存储持久 REPL 历史记录的文件路径。默认路径是 ~/.node_repl_history,可以被此变量覆盖。将该值设置为空字符串('' 或 ' ')将禁用持久 REPL 历史记录。
【Path to the file used to store the persistent REPL history. The default path is
~/.node_repl_history, which is overridden by this variable. Setting the value
to an empty string ('' or ' ') disables persistent REPL history.】
NODE_REPL_EXTERNAL_MODULE=file#>
Node.js 模块的路径,该模块将在内置 REPL 的位置加载。将此值覆盖为空字符串('')将使用内置 REPL。
【Path to a Node.js module which will be loaded in place of the built-in REPL.
Overriding this value to an empty string ('') will use the built-in REPL.】
NODE_SKIP_PLATFORM_CHECK=value#>
如果 value 等于 '1',在 Node.js 启动期间将跳过对支持平台的检查。Node.js 可能无法正确执行。在不支持的平台上遇到的任何问题都不会得到修复。
【If value equals '1', the check for a supported platform is skipped during
Node.js startup. Node.js might not execute correctly. Any issues encountered
on unsupported platforms will not be fixed.】
NODE_TLS_REJECT_UNAUTHORIZED=value#>
如果 value 等于 '0',TLS 连接的证书验证将被禁用。这会使 TLS 以及 HTTPS 的安全性降低。强烈不建议使用此环境变量。
【If value equals '0', certificate validation is disabled for TLS connections.
This makes TLS, and HTTPS by extension, insecure. The use of this environment
variable is strongly discouraged.】
NODE_V8_COVERAGE=dir#>
设置后,Node.js 将开始将 V8 JavaScript 代码覆盖率 和 源映射 数据输出到作为参数提供的目录(覆盖信息以 JSON 形式写入以 coverage 为前缀的文件)。
【When set, Node.js will begin outputting V8 JavaScript code coverage and
Source Map data to the directory provided as an argument (coverage
information is written as JSON to files with a coverage prefix).】
NODE_V8_COVERAGE 会自动传递到子进程,使得对调用 child_process.spawn() 系列函数的应用进行检测更加容易。NODE_V8_COVERAGE 可以设置为空字符串,以防止传播。
覆盖输出#>
【Coverage output】
覆盖率作为一个包含 脚本覆盖 个对象的数组输出,在顶层键 result 下:
【Coverage is output as an array of ScriptCoverage objects on the top-level
key result:】
{
"result": [
{
"scriptId": "67",
"url": "internal/tty.js",
"functions": []
}
]
}
源映射缓存#>
【Source map cache】
如果找到,源映射数据会被添加到 JSON 覆盖对象的顶层键 source-map-cache 中。
【If found, source map data is appended to the top-level key source-map-cache
on the JSON coverage object.】
source-map-cache 是一个对象,其键表示提取源映射的文件,值包括原始的源映射 URL(在键 url 中)、解析后的 Source Map v3 信息(在键 data 中)以及源文件的行长度(在键 lineLengths 中)。
{
"result": [
{
"scriptId": "68",
"url": "file:///absolute/path/to/source.js",
"functions": []
}
],
"source-map-cache": {
"file:///absolute/path/to/source.js": {
"url": "./path-to-map.json",
"data": {
"version": 3,
"sources": [
"file:///absolute/path/to/original.js"
],
"names": [
"Foo",
"console",
"info"
],
"mappings": "MAAMA,IACJC,YAAaC",
"sourceRoot": "./"
},
"lineLengths": [
13,
62,
38,
27
]
}
}
}
NO_COLOR=<any>#>
NO_COLOR 是 NODE_DISABLE_COLORS 的别名。该环境变量的值是任意的。
OPENSSL_CONF=file#>
在启动时加载 OpenSSL 配置文件。除了其他用途外,如果 Node.js 是使用 ./configure --openssl-fips 构建的,这可以用来启用符合 FIPS 的加密。
【Load an OpenSSL configuration file on startup. Among other uses, this can be
used to enable FIPS-compliant crypto if Node.js is built with
./configure --openssl-fips.】
如果使用 --openssl-config 命令行选项,则会忽略该环境变量。
【If the --openssl-config command-line option is used, the environment
variable is ignored.】
SSL_CERT_DIR=dir#>
如果启用了 --use-openssl-ca,这将覆盖并设置 OpenSSL 的包含受信任证书的目录。
【If --use-openssl-ca is enabled, this overrides and sets OpenSSL's directory
containing trusted certificates.】
请注意,除非显式设置子环境,否则此环境变量将被任何子进程继承,如果它们使用 OpenSSL,可能会导致它们信任与 Node 相同的证书颁发机构。
【Be aware that unless the child environment is explicitly set, this environment variable will be inherited by any child processes, and if they use OpenSSL, it may cause them to trust the same CAs as node.】
SSL_CERT_FILE=file#>
如果启用了 --use-openssl-ca,则此选项会覆盖并设置包含受信任证书的 OpenSSL 文件。
【If --use-openssl-ca is enabled, this overrides and sets OpenSSL's file
containing trusted certificates.】
请注意,除非显式设置子环境,否则此环境变量将被任何子进程继承,如果它们使用 OpenSSL,可能会导致它们信任与 Node 相同的证书颁发机构。
【Be aware that unless the child environment is explicitly set, this environment variable will be inherited by any child processes, and if they use OpenSSL, it may cause them to trust the same CAs as node.】
TZ#>
TZ 环境变量用于指定时区配置。
【The TZ environment variable is used to specify the timezone configuration.】
虽然 Node.js 并不支持所有类型的 在其他环境中处理 TZ 的方式,但它确实支持基本的 时区 ID(例如 'Etc/UTC'、'Europe/Paris' 或 'America/New_York')。
它可能支持其他一些缩写或别名,但这些强烈不推荐使用,也无法保证可用。
【While Node.js does not support all of the various ways that TZ is handled in
other environments, it does support basic timezone IDs (such as
'Etc/UTC', 'Europe/Paris', or 'America/New_York').
It may support a few other abbreviations or aliases, but these are strongly
discouraged and not guaranteed.】
$ TZ=Europe/Dublin node -pe "new Date().toString()"
Wed May 12 2021 20:30:48 GMT+0100 (Irish Standard Time)
UV_THREADPOOL_SIZE=size#>
将 libuv 线程池中使用的线程数设置为 size 个线程。
【Set the number of threads used in libuv's threadpool to size threads.】
Node.js 尽可能使用异步系统 API,但在这些 API 不存在的情况下,会使用 libuv 的线程池基于同步系统 API 创建异步 Node API。使用线程池的 Node.js API 有:
【Asynchronous system APIs are used by Node.js whenever possible, but where they do not exist, libuv's threadpool is used to create asynchronous node APIs based on synchronous system APIs. Node.js APIs that use the threadpool are:】
- 除文件监视器 API 和那些显式同步的 API 外,所有
fsAPI - 异步加密 API,例如
crypto.pbkdf2()、crypto.scrypt()、crypto.randomBytes()、crypto.randomFill()、crypto.generateKeyPair() dns.lookup()- 所有
zlibAPI,除了那些明确为同步的 API
由于 libuv 的线程池大小是固定的,这意味着如果由于某种原因其中任何一个 API 运行时间较长,那么其他在 libuv 线程池中运行的(看似无关联的)API 的性能也会受到影响。为了解决这个问题,一种潜在的解决方案是通过将 'UV_THREADPOOL_SIZE' 环境变量设置为大于 4 的值(其当前默认值)来增加 libuv 线程池的大小。更多信息,请参见 libuv 线程池文档。
【Because libuv's threadpool has a fixed size, it means that if for whatever
reason any of these APIs takes a long time, other (seemingly unrelated) APIs
that run in libuv's threadpool will experience degraded performance. In order to
mitigate this issue, one potential solution is to increase the size of libuv's
threadpool by setting the 'UV_THREADPOOL_SIZE' environment variable to a value
greater than 4 (its current default value). For more information, see the
libuv threadpool documentation.】
有用的 V8 选项#>
【Useful V8 options】
V8 有自己的一套命令行选项。任何提供给 node 的 V8 CLI 选项都会传递给 V8 处理。V8 的选项不保证稳定性。V8 团队本身也不认为它们是正式 API 的一部分,并保留随时更改的权利。同样,它们不在 Node.js 的稳定性保证范围内。很多 V8 选项仅对 V8 开发者有用。尽管如此,仍有一小部分 V8 选项在 Node.js 中广泛适用,并在此进行了文档说明:
【V8 has its own set of CLI options. Any V8 CLI option that is provided to node
will be passed on to V8 to handle. V8's options have no stability guarantee.
The V8 team themselves don't consider them to be part of their formal API,
and reserve the right to change them at any time. Likewise, they are not
covered by the Node.js stability guarantees. Many of the V8
options are of interest only to V8 developers. Despite this, there is a small
set of V8 options that are widely applicable to Node.js, and they are
documented here:】
--max-old-space-size=SIZE(以兆字节为单位)#>
【--max-old-space-size=SIZE (in megabytes)】
设置 V8 旧生代内存区域的最大内存大小。当内存使用接近上限时,V8 将花更多时间进行垃圾回收,以尝试释放未使用的内存。
【Sets the max memory size of V8's old memory section. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.】
在一台拥有 2 GiB 内存的机器上,可以考虑将此设置为 1536(1.5 GiB),以为其他用途留出一些内存并避免交换。
【On a machine with 2 GiB of memory, consider setting this to 1536 (1.5 GiB) to leave some memory for other uses and avoid swapping.】
$ node --max-old-space-size=1536 index.js
--max-semi-space-size=SIZE(以兆字节为单位)#>
【--max-semi-space-size=SIZE (in megabytes)】
设置 V8 的 清理垃圾收集器 的最大 半空格 大小,单位为 MiB(兆字节)。 增加半空间的最大大小可能会提高 Node.js 的吞吐量,但代价是更多的内存消耗。
【Sets the maximum semi-space size for V8's scavenge garbage collector in MiB (megabytes). Increasing the max size of a semi-space may improve throughput for Node.js at the cost of more memory consumption.】
由于 V8 堆的年轻代大小是半空间的三倍(参见 V8 中的 YoungGenerationSizeFromSemiSpaceSize),每增加 1 MiB 的半空间,会应用到三个独立的半空间,因此堆大小将增加 3 MiB。吞吐量的提高取决于你的工作负载(参见 #42511)。
【Since the young generation size of the V8 heap is three times (see
YoungGenerationSizeFromSemiSpaceSize in V8) the size of the semi-space,
an increase of 1 MiB to semi-space applies to each of the three individual
semi-spaces and causes the heap size to increase by 3 MiB. The throughput
improvement depends on your workload (see #42511).】
默认值为64位系统16 MiB,32位系统8 MiB。为了获得适合你应用的最佳配置,你应该在运行应用基准测试时尝试不同的 max-semi-space-size 值。
【The default value is 16 MiB for 64-bit systems and 8 MiB for 32-bit systems. To get the best configuration for your application, you should try different max-semi-space-size values when running benchmarks for your application.】
例如,在 64 位系统上进行基准测试:
【For example, benchmark on a 64-bit systems:】
for MiB in 16 32 64 128; do
node --max-semi-space-size=$MiB index.js
done