This should cover most use cases, potentially eliminating the need for the cumbersome npm config set script-shell "/bin/bash"; source ./.env; prefix in your Node commands, or even the extra dotenv library you might have added to your dependencies.
That said, I say "potentially" because the dotenv library offers features beyond what the native --env-file option supports — so if you're using advanced dotenv features, proceed with caution.
You can pass multiple --env-file arguments. Subsequent files override pre-existing variables defined in previous files.An error is thrown if the file does not exist.
Transactions make complex operations reliable and consistent, minimizing data corruption risks in modern applications.
node --env-file=.env --env-file=.development.env index.js
The --env-file-if-exists flag superclass --env-file in the sense that it first checks for file existence.