A simple trick for your dotenv files
Victor Ocnarescu
Posted on March 4, 2023
I'm sure most of you know and use dotenv files. They are great for storing app configs: everything that is likely to vary between deploys
MY_APP_KEY=supersecret
These app configs are stored in a convenient key/value pair in a dotenv file. But what may come as a surprise to you is that every value is a string
DAYS_UNTIL_DATA_DELETION=60
AWS_DISABLE=true
Both are in fact strings. Later on, when you will want to check if AWS is disabled, you will have to write this code (which I have seen over and over again in many projects)
if (process.env.AWS_DISABLE === "true") { ... } // what???
That is just silly! When faced with boolean values I always write them with yes/no instead of true/false.
Furthermore, I quote every value in the dotenv files to make sure that every developer that reads the file knows the values are strings.
Here is the result:
MY_APP_KEY="supersecret"
DAYS_UNTIL_DATA_DELETION="60"
AWS_DISABLE="yes"
Hope you enjoyed reading the article as much as I enjoyed writing it. And please do not store your boolean config values as strings. Give the yes/no option a try.
Posted on March 4, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.