Excellent and much-needed article. 👏 A lot of projects struggle with correct config setup. One thing that I would do slightly differently:
I think type conversion in config is not enough. Validating the required env vars with a library like joi gives you automatic type casting and won't let the process start with faulty or missing env vars. In some cases, a process can run for a long time until it needs a specific env var - like an SMTP address for email sending. These could cause random failures or - at worst - silent errors. Not starting the process and giving a clear message about env var issues is much cleaner.
This kind of issue happens more often than you may think. Large projects tend to have separate dev and devops teams. When a dev adds a new required env var to their .env file, they tell the devops team to add the same env var before rolling out the next deployment. This info can disappear among slack messages or email threads pretty easily.
That's a good shout, I didn't include it because your env variables should be mainly used directly and during app bootstrap where I expect things will fail if the vars aren't defined.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Excellent and much-needed article. 👏 A lot of projects struggle with correct config setup. One thing that I would do slightly differently:
I think type conversion in config is not enough. Validating the required env vars with a library like joi gives you automatic type casting and won't let the process start with faulty or missing env vars. In some cases, a process can run for a long time until it needs a specific env var - like an SMTP address for email sending. These could cause random failures or - at worst - silent errors. Not starting the process and giving a clear message about env var issues is much cleaner.
This kind of issue happens more often than you may think. Large projects tend to have separate dev and devops teams. When a dev adds a new required env var to their
.env
file, they tell the devops team to add the same env var before rolling out the next deployment. This info can disappear among slack messages or email threads pretty easily.That's a good shout, I didn't include it because your env variables should be mainly used directly and during app bootstrap where I expect things will fail if the vars aren't defined.