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
328 changes: 157 additions & 171 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,163 @@
node -C development app.js
```

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

<!-- YAML
added:
- v23.10.0
- v22.16.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/66431
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: v26.7.0
pr-url: https://github.com/nodejs/node/pull/64516

Check warning on line 815 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 @@ -1280,177 +1437,6 @@

Enable the experimental `node:bench` module and command-line benchmark runner.

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

<!-- YAML
added:
- v23.10.0
- v22.16.0
changes:
- version: v26.7.0
pr-url: https://github.com/nodejs/node/pull/64516
description: Marked as release candidate.
-->

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

<!-- YAML
added:
- v23.10.0
- v22.16.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-dtls`

<!-- YAML
Expand Down
11 changes: 6 additions & 5 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ programs.
#### 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 @@ -400,7 +400,7 @@ When the `permission` namespace is present in the configuration file, Node.js
automatically enables the `--permission` flag. Run with:

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

A configuration file, like the `NODE_OPTIONS` defined in an [`--env-file`][]
Expand All @@ -410,7 +410,7 @@ enable the Permission Model, the `allow-env` values these files define can only
narrow the access that [`--allow-env`][] grants, and never widen it:

```console
$ node --permission --allow-env=APP_* --experimental-config-file=node.config.json app.js
$ node --permission --allow-env=APP_* --config-file=node.config.json app.js
```

With `"allow-env": ["*"]` in `node.config.json`, only the variables starting with
Expand Down Expand Up @@ -539,6 +539,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
[`--env-file-if-exists`]: cli.md#--env-file-if-existsfile
[`--env-file`]: cli.md#--env-filefile
[`--permission-audit`]: cli.md#--permission-audit
Expand Down
Loading
Loading