Inconsistency in selecting .env file and undocumented behavior for 'dev'
Closed this issue · 2 comments
After struggling with figuring out why my environment variables weren't present for NODE_ENV=dev, I looked into the code and learned the following:
-
Despite explicitly setting NODE_ENV=dev, due to the special treatment of that environment specifier it loads .env first if it is present. (I had both .env and .env.dev.) I think this would be unexpected in most cases - more specification should usually take precedent over less specification.
-
The documentation states a few times that if the environment is not specified, it is assumed to be development. This is not strictly true - if no environment is specified it attempts to load .env. (Full stop.) It doesn't necessarily imply anything about the runtime environment, just which file it will look for.
IMO it would be better to make the filename lookup consistent for all environment specifiers, so there are no 'surprise' special cases. Specifically, if the environment is 'dev', then .env.dev is loaded if present. A nice fallback might be to look for .env as a fallback for both the case where the environment is not specified (as currently) and for the case where the environment-specific file is not present (e.g. if env=dev and .env.dev is not available, it tries to load .env as a second priority).
Hi @heidighunter I've started working with this, will get it fixed!
Thanks @heidighunter , Version 2 A new version is available, this is now resolved. It now selects file consistently and falls back to .env
configuration if not found.