Skip to content

Add --watch-path-if-exists #58436

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

Open
xzyfer opened this issue May 23, 2025 · 2 comments
Open

Add --watch-path-if-exists #58436

xzyfer opened this issue May 23, 2025 · 2 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@xzyfer
Copy link

xzyfer commented May 23, 2025

What is the problem this feature will solve?

With --watch and --env-file it became possible to replace fs watcher packages with native functionality with something like

node --env-file=.env --watch-path=.env --watch main.js

#50993 introduced --env-file-if-exists which makes it possible to replace dotenv loader libraries with native functionality with something like

node --env-file=.env --env-file-if-exists=.env.local --watch-path=.env --watch main.js

However there is no complimentary --watch-path-if-exists so it's not possible for the watcher to restart on changes to --env-file-if-exists paths.

Instead an error is thrown

Error: ENOENT: no such file or directory, watch '/Users/xzyfer/dev/my-ap/.env.local'

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

Add a flag (or other mechanism) complimentary to #50993 to indicate that a path should be watched only it's found, and to throw otherwise.

What alternatives have you considered?

touching the watched files before running node; invoking node via a shell script and "building up" the cli opts; pre-existing dotenv loaders such as the dotenv package.

@xzyfer xzyfer added the feature request Issues that request new features to be added to Node.js. label May 23, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests May 23, 2025
@juanarbol
Copy link
Member

I don't get it. What's the point of listen to events of files that may or may not exist?

This and env is a different story, if your env settings are not in a file, maybe you want to use the default env somehow.

Like, why would you like Node.js to restart itself if a file that is not critical changes? Help me understand why people need this.

@anonrig
Copy link
Member

anonrig commented May 24, 2025

I think cli commands are getting out of hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

3 participants