Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: make --env-file return warning when not found #53177

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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