A kata to explore what "store config in environment" really means :)
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-06-22 15:41:53 +02:00
configs starting point 2025-05-31 12:46:31 +02:00
.gitignore starting point 2025-05-31 12:46:31 +02:00
configuration.ts Better starting point 2025-06-22 15:41:53 +02:00
database.ts starting point 2025-05-31 12:46:31 +02:00
mailer.ts starting point 2025-05-31 12:46:31 +02:00
main.ts starting point 2025-05-31 12:46:31 +02:00
package-lock.json starting point 2025-05-31 12:46:31 +02:00
package.json starting point 2025-05-31 12:46:31 +02:00
README.md Better starting point 2025-06-22 15:41:53 +02:00
tsconfig.json starting point 2025-05-31 12:46:31 +02:00

12 Factor App Kata

Part 1 : centralized configuration

Introduction

Read the code, and notice how we can switch the Mailer API URL and the database URL form the JSON config files by setting the 'APP_ENVIRONMENT' variable.

For instance:

$ APP_ENVIRONMENT=production ts-node main.ts
Env:  production
Connecting to db app at database.example.org
Connecting to mailer API at:  https://mailer.example.org
Env:  local
Connecting to db app at localhost
Connecting to mailer API at:  http://localhost:8080/mailer/api

Changes we want to make

  • Add a "useTls" boolean to the database configuration
  • Introduce a pre-production environment in addition to the production env
  • Encrypt the password databse and the secret token for the mailer

Reflect on how big this changes would be in the state of the current code.

Part 2 : configuration as environment variables

Instructions

Go read the 12 Factor App documentation, especially the part about configuration:

=> https://12factor.net/config

Then refactor the code, getting rid of the 'configuration.ts' module completly.

Use a tool like direnv to store local configuration.

Then, try and apply the changes listed in part 1.

Finally, try and run the code using the "local" database and the "pre-production" mailer API.