You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve the way .env configuration file is loaded #49514
Make environment variables configuration file loading more fluent.
What is the feature you are proposing to solve the problem?
Instead of loading it using a CLI command like node --env-file .env, it would be event better to use a package.json field containing the environment filename, this way, Node can automatically load the environment variables every time a NPM script is running.
Another idea would be to let Node detect if a default .env file exists, and load it for each NPM script that is running. According to this idea, may be we could have a flag like --no-env-file or --env-file none to tell Node to not load environment file by default.
Another idea would be to let Node detect if a default .env file exists, and load it for each NPM script that is running.
This would be a breaking change, and by default opt-in as well as automatically detecting might create some serious security issues.
Instead of loading it using a CLI command like node --env-file .env, it would be event better to use a package.json field containing the environment filename, this way, Node can automatically load the environment variables every time a NPM script is running.
package.json fields are defined under WinterCG that would be hard to convince and requires a JSON parser that would be harder to implement since V8 is not initialized when parsing occurs.
Thanks for the fast reply, that was just some suggestions 😉, after doing a few tests on my side.
Unfortunately, from my point of view, I am not seeing all use cases / breaking changes / security issues that this may imply.
Feel free to close the issue if you think it's out of scope.
Activity
anonrig commentedon Sep 6, 2023
This would be a breaking change, and by default opt-in as well as automatically detecting might create some serious security issues.
package.jsonfields are defined under WinterCG that would be hard to convince and requires a JSON parser that would be harder to implement since V8 is not initialized when parsing occurs.xavierfoucrier commentedon Sep 6, 2023
Hi @anonrig 👋
Thanks for the fast reply, that was just some suggestions 😉, after doing a few tests on my side.
Unfortunately, from my point of view, I am not seeing all use cases / breaking changes / security issues that this may imply.
Feel free to close the issue if you think it's out of scope.
Have a nice day! 🌤️ 🌿
meduzen commentedon Oct 15, 2023
Jumping here, as I was searching for something similar.
For npm scripts specifically isn’t it a problem space that should be tackled by package managers like npm? 🤔
What led me here:
I wanted to avoid using
dotenvin a Vite config file, which is possible but ends up changing NPM scripts from:to