Skip to content

Commit 9fd217d

Browse files
marco-ippolitotargos
authored andcommitted
src: add config file support
PR-URL: #57016 Refs: #53787 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent d07bd79 commit 9fd217d

33 files changed

+1438
-1
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ doc: $(NODE_EXE) doc-only ## Build Node.js, and then build the documentation wit
809809

810810
out/doc:
811811
mkdir -p $@
812+
cp doc/node_config_json_schema.json $@
812813

813814
# If it's a source tarball, doc/api already contains the generated docs.
814815
# Just copy everything under doc/api over.

doc/api/cli.md

+63
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,69 @@ flows within the application. As such, it is presently recommended to be sure
919919
your application behaviour is unaffected by this change before using it in
920920
production.
921921

922+
### `--experimental-config-file`
923+
924+
<!-- YAML
925+
added: REPLACEME
926+
-->
927+
928+
> Stability: 1.0 - Early development
929+
930+
Use this flag to specify a configuration file that will be loaded and parsed
931+
before the application starts.
932+
Node.js will read the configuration file and apply the settings.
933+
The configuration file should be a JSON file
934+
with the following structure:
935+
936+
```json
937+
{
938+
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
939+
"experimental-transform-types": true,
940+
"import": [
941+
"amaro/transform"
942+
],
943+
"disable-warning": "ExperimentalWarning",
944+
"watch-path": "src",
945+
"watch-preserve-output": true
946+
}
947+
```
948+
949+
Only flags that are allowed in [`NODE_OPTIONS`][] are supported.
950+
No-op flags are not supported.
951+
Not all V8 flags are currently supported.
952+
953+
It is possible to use the [official JSON schema](../node_config_json_schema.json)
954+
to validate the configuration file, which may vary depending on the Node.js version.
955+
Each key in the configuration file corresponds to a flag that can be passed
956+
as a command-line argument. The value of the key is the value that would be
957+
passed to the flag.
958+
959+
For example, the configuration file above is equivalent to
960+
the following command-line arguments:
961+
962+
```bash
963+
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
964+
```
965+
966+
The priority in configuration is as follows:
967+
968+
1. NODE\_OPTIONS and command-line options
969+
2. Configuration file
970+
3. Dotenv NODE\_OPTIONS
971+
972+
Values in the configuration file will not override the values in the environment
973+
variables and command-line options, but will override the values in the `NODE_OPTIONS`
974+
env file parsed by the `--env-file` flag.
975+
976+
If duplicate keys are present in the configuration file, only
977+
the first key will be used.
978+
979+
The configuration parser will throw an error if the configuration file contains
980+
unknown keys or keys that cannot used in `NODE_OPTIONS`.
981+
982+
Node.js will not sanitize or perform validation on the user-provided configuration,
983+
so **NEVER** use untrusted configuration files.
984+
922985
### `--experimental-eventsource`
923986

924987
<!-- YAML

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Interpret the entry point as a URL.
166166
.It Fl -experimental-addon-modules
167167
Enable experimental addon module support.
168168
.
169+
.It Fl -experimental-config-file
170+
Enable support for experimental config file
171+
.
169172
.It Fl -experimental-import-meta-resolve
170173
Enable experimental ES modules support for import.meta.resolve().
171174
.

0 commit comments

Comments
 (0)