Skip to content

src: add `process.loadEnvFile` and `util.parseEnv`

Introduces 2 new functions to use the default .env parser.

process.loadEnvFile(path)

  • In order to load the .env file in the current directory:
process.loadEnvFile()
  • Load a specific path:
process.loadEnvFile('./development.env')

util.parseEnv(content)

  • In order to parse an existing string:
assert.deepStrictEqual(require('node:util').parseEnv('HELLO=world'), { HELLO: 'world' });

Fixes https://github.com/nodejs/node/issues/51413 Ref https://github.com/nodejs/node/issues/49148


Thank you Sentry for sponsoring this work!

Merge request reports

Loading