Configs
Every modern application runs on multiple environments and should have the ability to configure itself without changing code.
Config files
Config files located on ‘src/config/{filename}.js’. Each config file mostly unique and you should refer to module documentation (or framework config section)
Config files part of framework inheritance process .
Environment variables
The out of the box framework supports environment variables with the dotenv package.
Framework will grab and parse .env file on the root of the project directory to fill environment variables
Sample project ships with basic .env.example file
Do not use environment variables in code. Use it only inside config files. That allow you to track variables and split configs and codebase
Do not push the .env file to the version control system as it can contain passwords and keys. File should be queue per environment
Try to not overload the .env file with configuration and keep only private data on it. To manage non private data check NODE_ENV section
NODE_ENV
Depending on the NODE_ENV environment variable framework will load additional config files. Data from this files will be merged into main config with overwrite
This useful when you want to have something that depends on environment but do not want to overload .env file
Also it's a good practice to keep basic config on files rather then .env file.
Example:
export default {
variable1: 1,
variable2: 2
}
export default {
variable2: 3,
variable3: 4
}
On NON production environment
const sampleConfig = this.app.getConfig('sample');
// variable1: 1,
// variable2: 2
On PRODUCTION environment
const sampleConfig = this.app.getConfig('sample');
// variable1: 1,
// variable2: 3, <-- DIFFERENT
// variable3: 4 <-- NEW
You can use same approach for different environments (dev,stage, testing, etc)
API
getConfig(configName: string): {};
updateConfig(configName: string, config: {}): {};
Return config based on the config name. Also cached it on memory
const sampleConfig = this.app.getConfig('sample');
Update config based on config name. Return updated config
const sampleConfig = this.app.updateConfig('sample',{variableToUpdate:3, anotherVariable:4});