Skip to content

Commit

Permalink
src: make dotenv return warning when not found
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed May 29, 2024
1 parent 8e9686d commit 13af86d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dotenv-edge-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 13af86d

Please sign in to comment.