Dynamic configuration
Dynamic configuration means we can change the way the framework behaves by assigning system variables and passing them to our framework. These variables follow the ALL_CAPS
naming convention of a constant. Let’s begin by assigning a timeout based on the value of a DEBUG
environment variable. At the top of the config
file, we will capture the value of the DEBUG
environment variable:
const DEBUG = (process.env.DEBUG === undefined) ? false : (process.env.DEBUG === `true`)
This sets a default of false
if DEBUG
is not explicitly defined. Now, we can have a variable that extends the framework timeout when we explicitly execute a debug shortcut:
let timeout = DEBUG ? 10_000 : 16_000_000
Rule of thumb
Make your code readable with numeric separators. TypeScript supports underscores in place of commas with both integer and floating-point numbers. This makes 16_000_000
a valid integer while making the code more readable to humans.
We can find the timeout...