diff --git a/doc/api/cli.md b/doc/api/cli.md index 989a8cce13aa46..0bda4426cff709 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -905,6 +905,29 @@ Export keyword before a key is ignored: export USERNAME="nodejs" # will result in `nodejs` as the value. ``` +Additionally sections can be used to have a more granular control of +the environment variables within a single file. + +Sections can be defined in the file and then targeted by including a hash character +followed by their name as the flag's argument. Multiple sections can be specified and +if a variable is defined in multiple sections the latest instance of the variable in +the file overrides the others. + +For example given the following file: + +```text +MY_VAR = 'my top-level variable' + +[dev] +MY_VAR = 'my variable for development' + +[prod] +MY_VAR = 'my variable for production' +``` + +`--env-file=config#dev` will make it so that the variable's value being used is +taken from the `dev` section. + If you want to load environment variables from a file that may not exist, you can use the [`--env-file-if-exists`][] flag instead. diff --git a/doc/api/process.md b/doc/api/process.md index b3c74c99ec49b4..3db6bc06a50bc4 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2791,6 +2791,10 @@ added: * `path` {string | URL | Buffer | undefined}. **Default:** `'./.env'` +* `options` + + * `sections` {string\[]} (optional) The sections to use. + Loads the `.env` file into `process.env`. Usage of `NODE_OPTIONS` in the `.env` file will not have any effect on Node.js. diff --git a/doc/api/util.md b/doc/api/util.md index 1de5ea1515e918..540a94af264da7 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2133,7 +2133,7 @@ $ node negate.js --no-logfile --logfile=test.log --color --no-color { logfile: 'test.log', color: false } ``` -## `util.parseEnv(content)` +## `util.parseEnv(content, sections)`