diff --git a/doc/api/cli.md b/doc/api/cli.md index dda77612f215aa..96348c0639f07b 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -732,6 +732,8 @@ in the file, the value from the environment takes precedence. You can pass multiple `--env-file` arguments. Subsequent files override pre-existing variables defined in previous files. +If the file is not found, a warning will be printed. + ```bash node --env-file=.env --env-file=.development.env index.js ``` diff --git a/src/node.cc b/src/node.cc index 87488cf0e015fd..37a6056d50c547 100644 --- a/src/node.cc +++ b/src/node.cc @@ -845,7 +845,7 @@ static ExitCode InitializeNodeWithArgsInternal( errors->push_back(file_path + ": invalid format"); break; case Dotenv::ParseResult::FileError: - errors->push_back(file_path + ": not found"); + fprintf(stderr, "Warning: Requested .env file not found\n\n"); break; default: UNREACHABLE(); diff --git a/test/parallel/test-dotenv-edge-cases.js b/test/parallel/test-dotenv-edge-cases.js index f8cd262c8a8092..236ca6168b897a 100644 --- a/test/parallel/test-dotenv-edge-cases.js +++ b/test/parallel/test-dotenv-edge-cases.js @@ -48,8 +48,8 @@ describe('.env supports edge cases', () => { [ '--env-file=.env', '--eval', code ], { cwd: __dirname }, ); - assert.notStrictEqual(child.stderr.toString(), ''); - assert.strictEqual(child.code, 9); + assert.ok(child.stderr.includes('Requested .env file not found')); + assert.strictEqual(child.code, 0); }); it('should not override existing environment variables but introduce new vars', async () => {