- Always use flat structure in JSON files (create logical hierarchy in your app when building config with loader)
- For config keys, use
CAPITALIZED_WITH_UNDERSCORES
case, as is conventional for env variables - Keep all variables used by loader in you default config, add to VCS. Store default values or placeholders. It will be a perfect starting point for custom configs.
- Keep your configuration interface minimal. If you don't need to configure parameter for different environments, use constant parameter without loader.
- Even though you can use plain
JSON
for config values, preferJSONc
and add comments to your variables. - Keep your
.env.jsonc
well structured and well documented. Setting up the configuration should not require thorough prior knowledge of the implementation.
Examples:
- Setting default of
SQL_PORT
to5432
is a good idea if you are using PostgreSQL. Similarly for MySQL, a reasonable default value would be3306
- Default
3000
for your HTTP server might be reasonable, if it is a convention of your developer team and/or its is wired e.g. in your Dockerfile anyway. Developers can still change it collides with any local running processes. - Using credentials to your testing infrastructure as a default is wrong, even though it would make setup for developers easier in some scenarios. It would be confidential info in your repo history.
- If you find your configuration file harder to navigate through, use sections seperated by a newline with a comment
- If name is not self-explanatory, use brief comment to explain how is the value interpreted
- Do not include tautological comments (
"SERVER_PORT": 3000, // server port
)