05/11/2020
Environment Variable Booleans

Ugly:

if (process.env.MYVAR === 'true')
if (process.env.MYVAR === '1')

Pretty:

if (!!+process.env.MYVAR) // for boolean env vars for =0/=1

This expression uses JavaScript’s string to number dynamic casting of +process.env.VAR and double negates it (!!) to provide the user with true or false results.

When working with environment variables, you sometimes want to have boolean flags. The problem is, envvars are inherintly strings. The better way when working with boolean environment variables is by using 1 or 0 instead.