diff --git a/doc/api/util.md b/doc/api/util.md index 5c83b6a3bff961..9af2dc2fc63497 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2135,6 +2135,37 @@ $ node negate.js --no-logfile --logfile=test.log --color --no-color { logfile: 'test.log', color: false } ``` +## `util.loadEnvFile(path)` + + + +> Stability: 1.1 - Active development + +* `path` {string | URL | Buffer | undefined}. **Default:** `'./.env'` + +Parses the `.env` file and returns an object containing its values. + +```cjs +const { loadEnvFile } = require('node:util'); + +// The `.env` file contains the following line: `MY_VAR = my variable` + +loadEnvFile(); +// Returns { MY_VAR: 'my variable' } +``` + +```mjs +import { loadEnvFile } from 'node:util'; + +// The `.env` file contains the following line: `MY_VAR = my variable` + +loadEnvFile(); +// Returns { MY_VAR: 'my variable' } +``` + ## `util.parseEnv(content)`