Working on a huge application with lots of legacy code, I often encounter environment "checks":
db_name = Rails.env.production? ? 'staging_db' : 'production_db' ... desired_processes_count = Rails.env.production? ? 6 : 1 ... Rails.env.production? ? "index,follow" : "noindex,nofollow"
and so on. It's Ruby on Rails, but I guess the question is applicable for a wider range of projects, despite the technology.
The app does use
.dotenv, and in the
.env file, there are:
and that's about it.
In my opinion, readability increases significantly if all of the aforementioned examples:
- PROCESSES_COUNT (not really readable though, could be more descriptive)
are stored as environment variables - it does not have to be
.env, obviously, just a single configuration file with all of them.
I am not an expert though.
How can I evaluate if the variable qualifies as an environment variable?
Is there any rule of thumb, set of best practices? Or is it a completely opinion-based question?