Skip to content

Commit 13af86d

Browse files
committed
src: make dotenv return warning when not found
1 parent 8e9686d commit 13af86d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/api/cli.md

+2
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ in the file, the value from the environment takes precedence.
732732
You can pass multiple `--env-file` arguments. Subsequent files override
733733
pre-existing variables defined in previous files.
734734

735+
If the file is not found, a warning will be printed.
736+
735737
```bash
736738
node --env-file=.env --env-file=.development.env index.js
737739
```

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static ExitCode InitializeNodeWithArgsInternal(
845845
errors->push_back(file_path + ": invalid format");
846846
break;
847847
case Dotenv::ParseResult::FileError:
848-
errors->push_back(file_path + ": not found");
848+
fprintf(stderr, "Warning: Requested .env file not found\n\n");
849849
break;
850850
default:
851851
UNREACHABLE();

test/parallel/test-dotenv-edge-cases.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ describe('.env supports edge cases', () => {
4848
[ '--env-file=.env', '--eval', code ],
4949
{ cwd: __dirname },
5050
);
51-
assert.notStrictEqual(child.stderr.toString(), '');
52-
assert.strictEqual(child.code, 9);
51+
assert.ok(child.stderr.includes('Requested .env file not found'));
52+
assert.strictEqual(child.code, 0);
5353
});
5454

5555
it('should not override existing environment variables but introduce new vars', async () => {

0 commit comments

Comments
 (0)