Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 155 additions & 92 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,161 @@
node -C development app.js
```

### `--config-file=path`, `--config-file`

<!-- YAML
added: v23.10.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/66431

Check warning on line 540 in doc/api/cli.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: This flag was renamed from `--experimental-config-file` to
`--config-file` and is now stable. `--experimental-config-file`
and `--experimental-default-config-file` are kept as aliases.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/64516

Check warning on line 545 in doc/api/cli.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Marked as 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 `--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`

<!-- YAML
Expand Down Expand Up @@ -996,98 +1151,6 @@

Enable experimental import support for `.node` addons.

### `--experimental-config-file=path`, `--experimental-config-file`

<!-- YAML
added: v23.10.0
-->

> Stability: 1.0 - Early development

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` contain configuration specific to that subsystem.

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`

<!-- YAML
added: v23.10.0
-->

> 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-eventsource`

<!-- YAML
Expand Down
12 changes: 7 additions & 5 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ both to the top-level `node:fs` functions and to the equivalent
#### Configuration file support

In addition to passing permission flags on the command line, they can also be
declared in a Node.js configuration file when using the experimental
\[`--experimental-config-file`]\[] flag. Permission options must be placed inside
the `permission` top-level object.
declared in a Node.js configuration file when using the [`--config-file`][]
flag. Permission options must be placed inside the `permission` top-level
object.

Example `node.config.json`:

Expand All @@ -280,10 +280,11 @@ Example `node.config.json`:
}
```

Run with the configuration file:
When the `permission` namespace is present in the configuration file, Node.js
automatically enables the `--permission` flag. Run with:

```console
$ node --permission --experimental-default-config-file app.js
$ node --config-file app.js
```

#### Using the Permission Model with `npx`
Expand Down Expand Up @@ -396,6 +397,7 @@ Developers relying on --permission to sandbox untrusted code should be aware tha
[`--allow-openssl-store`]: cli.md#--allow-openssl-store
[`--allow-wasi`]: cli.md#--allow-wasi
[`--allow-worker`]: cli.md#--allow-worker
[`--config-file`]: cli.md#--config-filepath---config-file
[`--permission-audit`]: cli.md#--permission-audit
[`--permission`]: cli.md#--permission
[`crypto.createPrivateKey()`]: crypto.md#cryptocreateprivatekeykey
Expand Down
5 changes: 2 additions & 3 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,9 @@ test runner functionality:
* `--experimental-test-tag-filter` - Filter values are validated by the parent
process and re-emitted to child processes
* `--watch` - Watch mode is handled at the parent level
* `--experimental-default-config-file` - Config file loading is handled by the parent
* `--test-reporter` - Reporting is managed by the parent process
* `--test-reporter-destination` - Output destinations are controlled by the parent
* `--experimental-config-file` - Config file paths are managed by the parent
* `--config-file` - Config file paths are managed by the parent
* `--test-randomize` - Randomization is managed by the parent process and
propagated to child processes
* `--test-random-seed` - Randomization seed is managed by the parent process and
Expand Down Expand Up @@ -4945,7 +4944,7 @@ test.describe('my suite', (suite) => {
[`suite()`]: #suitename-options-fn
[`test()`]: #testname-options-fn
[code coverage]: #collecting-code-coverage
[configuration files]: cli.md#--experimental-config-filepath---experimental-config-file
[configuration files]: cli.md#--config-filepath---config-file
[describe options]: #describename-options-fn
[it options]: #testname-options-fn
[module customization hooks]: module.md#customization-hooks
Expand Down
Loading
Loading