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 选项如下列所示。如果一个选项同时支持 --XX 和 --no-XX 变体,它们都被支持,但下面的列表中仅包含其中一个。

【Node.js options that are allowed are in the following list. If an option supports both --XX and --no-XX variants, they are both supported but only one is included in the list below.】

  • --allow-addons
  • --allow-child-process
  • --allow-fs-read
  • --allow-fs-write
  • --allow-inspector
  • --allow-wasi
  • --allow-worker
  • --conditions-C
  • --cpu-prof-dir
  • --cpu-prof-interval
  • --cpu-prof-name
  • --cpu-prof
  • --diagnostic-dir
  • --disable-proto
  • --disable-sigusr1
  • --disable-warning
  • --disable-wasm-trap-handler
  • --dns-result-order
  • --enable-fips
  • --enable-network-family-autoselection
  • --enable-source-maps
  • --entry-url
  • --experimental-abortcontroller
  • --experimental-addon-modules
  • --experimental-detect-module
  • --experimental-eventsource
  • --experimental-import-meta-resolve
  • --experimental-json-modules
  • --experimental-loader
  • --experimental-modules
  • --experimental-print-required-tla
  • --experimental-require-module
  • --experimental-shadow-realm
  • --experimental-specifier-resolution
  • --experimental-test-isolation
  • --experimental-top-level-await
  • --experimental-transform-types
  • --experimental-vm-modules
  • --experimental-wasi-unstable-preview1
  • --experimental-webstorage
  • --force-context-aware
  • --force-fips
  • --force-node-api-uncaught-exceptions-policy
  • --frozen-intrinsics
  • --heap-prof-dir
  • --heap-prof-interval
  • --heap-prof-name
  • --heap-prof
  • --heapsnapshot-near-heap-limit
  • --heapsnapshot-signal
  • --http-parser
  • --icu-data-dir
  • --import
  • --input-type
  • --insecure-http-parser
  • --inspect-brk
  • --inspect-port--debug-port
  • --inspect-publish-uid
  • --inspect-wait
  • --inspect
  • --localstorage-file
  • --max-http-header-size
  • --max-old-space-size-percentage
  • --napi-modules
  • --network-family-autoselection-attempt-timeout
  • --no-addons
  • --no-async-context-frame
  • --no-deprecation
  • --no-experimental-global-navigator
  • --no-experimental-repl-await
  • --no-experimental-sqlite
  • --no-experimental-strip-types
  • --no-experimental-websocket
  • --no-extra-info-on-fatal-exception
  • --no-force-async-hooks-checks
  • --no-global-search-paths
  • --no-network-family-autoselection
  • --no-strip-types
  • --no-warnings
  • --node-memory-debug
  • --openssl-config
  • --openssl-legacy-provider
  • --openssl-shared-config
  • --pending-deprecation
  • --permission
  • --preserve-symlinks-main
  • --preserve-symlinks
  • --prof-process
  • --redirect-warnings
  • --report-compact
  • --report-dir--report-directory
  • --report-exclude-env
  • --report-exclude-network
  • --report-filename
  • --report-on-fatalerror
  • --report-on-signal
  • --report-signal
  • --report-uncaught-exception
  • --require-r
  • --secure-heap-min
  • --secure-heap
  • --snapshot-blob
  • --test-coverage-branches
  • --test-coverage-exclude
  • --test-coverage-functions
  • --test-coverage-include
  • --test-coverage-lines
  • --test-global-setup
  • --test-isolation
  • --test-name-pattern
  • --test-only
  • --test-reporter-destination
  • --test-reporter
  • --test-rerun-failures
  • --test-shard
  • --test-skip-pattern
  • --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-deprecation
  • --trace-env-js-stack
  • --trace-env-native-stack
  • --trace-env
  • --trace-event-categories
  • --trace-event-file-pattern
  • --trace-events-enabled
  • --trace-exit
  • --trace-require-module
  • --trace-sigint
  • --trace-sync-io
  • --trace-tls
  • --trace-uncaught
  • --trace-warnings
  • --track-heap-objects
  • --unhandled-rejections
  • --use-bundled-ca
  • --use-env-proxy
  • --use-largepages
  • --use-openssl-ca
  • --use-system-ca
  • --v8-pool-size
  • --watch-kill-signal
  • --watch-path
  • --watch-preserve-output
  • --watch
  • --zero-fill-buffers

允许的 V8 选项是:

【V8 options that are allowed are:】

  • --abort-on-uncaught-exception
  • --disallow-code-generation-from-strings
  • --enable-etw-stack-walking
  • --expose-gc
  • --interpreted-frames-native-stack
  • --jitless
  • --max-old-space-size
  • --max-semi-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 上可用。

--enable-etw-stack-walking 仅在 Windows 上可用。