From c260c9cd5c6bdcf89ee67190c82d35043796e6ab Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Thu, 1 Oct 2026 11:47:11 +0200 Subject: [PATCH 1/2] src: mark config file as stable Signed-off-by: Marco Ippolito --- doc/api/cli.md | 328 +++++++++--------- doc/api/permissions.md | 11 +- doc/api/test.md | 5 +- doc/node.1 | 256 +++++++------- lib/internal/bench_runner/cli.js | 4 +- lib/internal/debugger/inspect_helpers.js | 3 +- lib/internal/main/watch_mode.js | 4 +- lib/internal/process/pre_execution.js | 8 - lib/internal/test_runner/runner.js | 4 +- src/node_config_file.cc | 24 +- src/node_config_file.h | 2 +- src/node_options.cc | 7 +- src/node_options.h | 2 +- ...fig-file.test.mjs => config-file.test.mjs} | 4 +- test/parallel/test-bench-cli.js | 2 +- test/parallel/test-cli-node-options-docs.js | 1 - test/parallel/test-cli-options-as-flags.js | 4 +- test/parallel/test-config-file.js | 135 ++++--- test/parallel/test-debugger-no-inspect-brk.js | 8 + test/parallel/test-permission-config-file.mjs | 18 +- .../test-permission-env-config-file.js | 8 +- test/parallel/test-runner-cli.js | 4 +- test/parallel/test-runner-flag-propagation.js | 8 +- test/sequential/test-watch-mode.mjs | 6 +- 24 files changed, 433 insertions(+), 423 deletions(-) rename test/fixtures/test-runner/options-propagation/{experimental-config-file.test.mjs => config-file.test.mjs} (50%) diff --git a/doc/api/cli.md b/doc/api/cli.md index b57714a0bfa2..56f429784179 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -799,6 +799,163 @@ For example, to run a module with "development" resolutions: node -C development app.js ``` +### `--config-file=path`, `--config-file` + + + +If present, Node.js will look for a configuration file at the specified path. +If the path is not specified, Node.js will look for a `node.config.json` file +in the current working directory. +To specify a custom path, use the `--config-file=path` form. +The space-separated `--config-file path` form is not supported. +Node.js will read the configuration file and apply the settings. The +configuration file should be a JSON file with the following structure. `vX.Y.Z` +in the `$schema` must be replaced with the version of Node.js you are using or +`latest-vX.x` for the latest version of that major release line. + +```json +{ + "$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json", + "nodeOptions": { + "import": [ + "amaro/strip" + ], + "watch-path": "src", + "watch-preserve-output": true + }, + "test": { + "test-isolation": "process" + }, + "watch": { + "watch-preserve-output": true + } +} +``` + +The configuration file supports namespace-specific options: + +* The `nodeOptions` field contains CLI flags that are allowed in [`NODE_OPTIONS`][]. + +* Namespace fields like `test`, `watch`, and `permission` contain configuration specific to that subsystem. + +The configuration file can target a specific Node.js major version with +`nodeVersion`: + +```json +{ + "nodeVersion": 25, + "nodeOptions": { + "watch-path": "src" + } +} +``` + +To keep multiple version-specific configurations in the same file, use the +`configs` array. Node.js will use the first entry whose `nodeVersion` matches +the current Node.js major version: + +```json +{ + "$schema": "https://nodejs.org/dist/latest-v26.x/docs/node-config-schema.json", + "configs": [ + { + "nodeVersion": 25, + "config": { + "$schema": "https://nodejs.org/dist/latest-v25.x/docs/node-config-schema.json", + "nodeOptions": { + "watch-path": "src" + } + } + } + ] +} +``` + +When `configs` is used, the top level may only contain `$schema` and +`configs`. Each `configs` item must define an integer `nodeVersion` and an +object `config`. A single top-level config does not require `nodeVersion`, but +if present it must match the current Node.js major version. + +When a namespace is present in the +configuration file, Node.js automatically enables the corresponding flag +(e.g., `--test`, `--watch`, `--permission`). This allows you to configure +subsystem-specific options without explicitly passing the flag on the command line. + +For example: + +```json +{ + "test": { + "test-isolation": "process" + } +} +``` + +is equivalent to: + +```bash +node --test --test-isolation=process +``` + +To disable the automatic flag while still using namespace options, you can +explicitly set the flag to `false` within the namespace: + +```json +{ + "test": { + "test": false, + "test-isolation": "process" + } +} +``` + +No-op flags are not supported. +Not all V8 flags are currently supported. + +It is possible to use the [official JSON schema](../node-config-schema.json) +to validate the configuration file, which may vary depending on the Node.js version. +Each key in the configuration file corresponds to a flag that can be passed +as a command-line argument. The value of the key is the value that would be +passed to the flag. + +For example, the configuration file above is equivalent to +the following command-line arguments: + +```bash +node --import amaro/strip --watch-path=src --watch-preserve-output --test-isolation=process +``` + +The priority in configuration is as follows: + +1. NODE\_OPTIONS and command-line options +2. Dotenv NODE\_OPTIONS +3. Configuration file + +Values in the configuration file will not override the values in the environment +variables, command-line options, or the `NODE_OPTIONS` env file parsed by the +`--env-file` flag. + +Keys cannot be duplicated within the same or different namespaces. + +The configuration parser will throw an error if the configuration file contains +unknown keys or keys that cannot be used in a namespace. + +Node.js will not sanitize or perform validation on the user-provided configuration, +so **NEVER** use untrusted configuration files. + ### `--cpu-prof` - -> Stability: 1.2 - Release candidate - -If present, Node.js will look for a configuration file at the specified path. -If the path is not specified, Node.js will look for a `node.config.json` file -in the current working directory. -To specify a custom path, use the `--experimental-config-file=path` form. -The space-separated `--experimental-config-file path` form is not supported. -The alias `--experimental-default-config-file` is equivalent to -`--experimental-config-file` without an argument. -Node.js will read the configuration file and apply the settings. The -configuration file should be a JSON file with the following structure. `vX.Y.Z` -in the `$schema` must be replaced with the version of Node.js you are using or -`latest-vX.x` for the latest version of that major release line. - -```json -{ - "$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json", - "nodeOptions": { - "import": [ - "amaro/strip" - ], - "watch-path": "src", - "watch-preserve-output": true - }, - "test": { - "test-isolation": "process" - }, - "watch": { - "watch-preserve-output": true - } -} -``` - -The configuration file supports namespace-specific options: - -* The `nodeOptions` field contains CLI flags that are allowed in [`NODE_OPTIONS`][]. - -* Namespace fields like `test`, `watch`, and `permission` contain configuration specific to that subsystem. - -The configuration file can target a specific Node.js major version with -`nodeVersion`: - -```json -{ - "nodeVersion": 25, - "nodeOptions": { - "watch-path": "src" - } -} -``` - -To keep multiple version-specific configurations in the same file, use the -`configs` array. Node.js will use the first entry whose `nodeVersion` matches -the current Node.js major version: - -```json -{ - "$schema": "https://nodejs.org/dist/latest-v26.x/docs/node-config-schema.json", - "configs": [ - { - "nodeVersion": 25, - "config": { - "$schema": "https://nodejs.org/dist/latest-v25.x/docs/node-config-schema.json", - "nodeOptions": { - "watch-path": "src" - } - } - } - ] -} -``` - -When `configs` is used, the top level may only contain `$schema` and -`configs`. Each `configs` item must define an integer `nodeVersion` and an -object `config`. A single top-level config does not require `nodeVersion`, but -if present it must match the current Node.js major version. - -When a namespace is present in the -configuration file, Node.js automatically enables the corresponding flag -(e.g., `--test`, `--watch`, `--permission`). This allows you to configure -subsystem-specific options without explicitly passing the flag on the command line. - -For example: - -```json -{ - "test": { - "test-isolation": "process" - } -} -``` - -is equivalent to: - -```bash -node --test --test-isolation=process -``` - -To disable the automatic flag while still using namespace options, you can -explicitly set the flag to `false` within the namespace: - -```json -{ - "test": { - "test": false, - "test-isolation": "process" - } -} -``` - -No-op flags are not supported. -Not all V8 flags are currently supported. - -It is possible to use the [official JSON schema](../node-config-schema.json) -to validate the configuration file, which may vary depending on the Node.js version. -Each key in the configuration file corresponds to a flag that can be passed -as a command-line argument. The value of the key is the value that would be -passed to the flag. - -For example, the configuration file above is equivalent to -the following command-line arguments: - -```bash -node --import amaro/strip --watch-path=src --watch-preserve-output --test-isolation=process -``` - -The priority in configuration is as follows: - -1. NODE\_OPTIONS and command-line options -2. Dotenv NODE\_OPTIONS -3. Configuration file - -Values in the configuration file will not override the values in the environment -variables, command-line options, or the `NODE_OPTIONS` env file parsed by the -`--env-file` flag. - -Keys cannot be duplicated within the same or different namespaces. - -The configuration parser will throw an error if the configuration file contains -unknown keys or keys that cannot be used in a namespace. - -Node.js will not sanitize or perform validation on the user-provided configuration, -so **NEVER** use untrusted configuration files. - -### `--experimental-default-config-file` - - - -> Stability: 1.0 - Early development - -This flag is an alias for `--experimental-config-file` without an argument. -If present, Node.js will look for a -`node.config.json` file in the current working directory and load it as a -configuration file. - ### `--experimental-dtls`