If I understand correctly what they're writing here:
Should I have multiple .env files?
No. We strongly recommend against having a "main" .env file and an "environment" .env file like .env.test. Your config should vary between deploys, and you should not be sharing values between environments.
This doesn't mean that you shouldn't have multiple env files, but rather that you shouldn't have one main.env
file with all the default configuration and additional env files (one per environment) that inherit from main.env
and override certain values.
The reason why it's not recommended is that with such a configuration it's difficult to understand "where a specific value is coming from?" (from which one of the following: main-env-file, specific-env-file, env-variable, code-default and etc).
That said, if you create multiple env files without such a "main" this means that you'll need to duplicate many of the values all over the different env files, which is better because of explicitness, but has the downside of duplication/verbosity.
Configuration is not trivial IMO and while you have only a small project it doesn't matter much how you choose to implement, but if we're talking about something more critical like a company's product, then there are many solutions available out there, some are open-source and free, some cost money, but it's worth doing your research and figure out which one provides you the benefits that are more meaningful to your use-case.
Some of the more popular tools are: Puppet, Ansible, and Chef.
.env
files hold secrets like API keys and crypto hashes, they're not supposed to be commited and part of your repo. The whole point of.env
files is to have one per machine, so you can precisely have content in them depending on the machine/environment : dev, staging, production. Or am I missing something? – Midi.env
file assuming they are checked in the repo. Secrets should be handled separately & securely by a dedicated mechanism! Now, not checking env files into a repo creates a different problem: where do we keep it? how do we back it up? how do we track changes? – Lemmie