12 Factor App lists the fact that environment variables are a language-agnostic standard as one of the primary reasons to prefer environment variables for configuration. And that is a real benefit: I can’t think of a programming language that doesn’t have built-in support for environment variables.
However, using environment variables punts the complexity from the app to the operations and tooling side. It is easy for apps to read environment variables, but managing environment variables typically requires specialized tooling. In particular, in order to run different apps simultaneously with different environment variables, you need containers or some other tool that sets up environment variables.
For local development using environment variables, I typically have a `local.env` file checked in to GitHub that contains environment variables for local dev: MongoDB pointed to localhost:27017, test API keys, etc. I then use the
node-env npm package to read `.env` files (
dotenv is a common alternative), and run scripts like this: