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

--env-file watch #54001

Closed
OliverJAsh opened this issue Jul 23, 2024 · 3 comments · Fixed by #54109
Closed

--env-file watch #54001

OliverJAsh opened this issue Jul 23, 2024 · 3 comments · Fixed by #54109
Labels
dotenv Issues and PRs related to .env file parsing feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. watch-mode Issues and PRs related to watch mode

Comments

@OliverJAsh
Copy link

What is the problem this feature will solve?

We already have --env-file and --watch:

$ node --env-file=.env --watch test.js

However, it seems we're missing the ability to watch the env file. The command above will not restart the script when the env file changes.

--watch-path=.env doesn't help either. It does restart the script when the env file changes, however the env file is not loaded again, so the script only has access to the environment variables that were loaded when the command was first ran.

What is the feature you are proposing to solve the problem?

A flag to watch the env file e.g. --watch-env-file.

What alternatives have you considered?

No response

@OliverJAsh OliverJAsh added the feature request Issues that request new features to be added to Node.js. label Jul 23, 2024
@MoLow MoLow added good first issue Issues that are suitable for first-time contributors. watch-mode Issues and PRs related to watch mode labels Jul 23, 2024
@MoLow
Copy link
Member

MoLow commented Jul 23, 2024

this should probably be the default, without an extra flag

@RedYetiDev RedYetiDev added the dotenv Issues and PRs related to .env file parsing label Jul 23, 2024
@tniessen
Copy link
Member

--watch-path=.env doesn't help either. It does restart the script when the env file changes, however the env file is not loaded again, so the script only has access to the environment variables that were loaded when the command was first ran.

I assume that the node process loads .env, then starts the actual application as a child process with the same --env-file flag. This should cause the child process to load the environment file upon start, however, the child process inherits the environment variables from the parent process, and inherited environment variables take precedence over variables read from .env, so you wouldn't see any changes to existing environment variables.

To test this hypothesis, could you check if you can see new variables in the child process when you add a new entry to .env while --watch is running?

@OliverJAsh
Copy link
Author

To test this hypothesis, could you check if you can see new variables in the child process when you add a new entry to .env while --watch is running?

I just tested this and I can! You're right.

HBSPS added a commit to HBSPS/node that referenced this issue Jul 25, 2024
observe env files in --watch mode through the watcher's filterFile and
forward changes to the childProcess

Fixes: nodejs#54001
HBSPS added a commit to HBSPS/node that referenced this issue Jul 25, 2024
observe env files in `--watch` mode through the watcher's filterFile and
forward changes to the childProcess

Fixes: nodejs#54001
marekpiechut added a commit to marekpiechut/node that referenced this issue Jul 29, 2024
Make sure we watch and reload on env file changes.

Ignore env file in parent process, so child process can reload
current vars when we recreate it.

Fixes: nodejs#54001
marekpiechut added a commit to marekpiechut/node that referenced this issue Jul 29, 2024
Make sure we watch and reload on env file changes.

Ignore env file in parent process, so child process can reload
current vars when we recreate it.

Fixes: nodejs#54001
marekpiechut added a commit to marekpiechut/node that referenced this issue Jul 29, 2024
Make sure we watch and reload on env file changes.

Ignore env file in parent process, so child process can reload
current vars when we recreate it.

Fixes: nodejs#54001
nodejs-github-bot pushed a commit that referenced this issue Aug 5, 2024
Make sure we watch and reload on env file changes.

Ignore env file in parent process, so child process can reload
current vars when we recreate it.

Fixes: #54001
PR-URL: #54109
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
targos pushed a commit that referenced this issue Aug 14, 2024
Make sure we watch and reload on env file changes.

Ignore env file in parent process, so child process can reload
current vars when we recreate it.

Fixes: #54001
PR-URL: #54109
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotenv Issues and PRs related to .env file parsing feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. watch-mode Issues and PRs related to watch mode
Projects
None yet
4 participants