This project is part of the flipr family.
node-flipr-yaml is a flipr source for retrieving flipr configuration data from yaml files.
How does it work?
The examples below show you how to create the flipr yaml source. A source by itself isn't very useful. You'll still need to give the source to flipr, so that it can use it to do awesome things. See the flipr documentation for how to use a source.
Here's the simplest example:
---# Here's a basic YAML config file. Assume it exists at config/simple.yamlsomeConfigKey:description: >This is some config key that has some value.value: someValue
const FliprYaml = ;const source =filePath: 'config/simple.yaml';source;
Validating your yaml files
flipr-yaml has the ability to validate your yaml files. This is very useful if you're storing your yaml files alongside your app code and using a CICD pipeline to automatically deploy changes. You can create a unit test that runs
flipr-yaml's config validation, thereby catching any breaking changes to the config before they are released. The validation only catches syntax errors in the config. If you provide flipr-yaml the flipr rules you use in your application, it will catch some logical errors as well, like the values of a percent rule not adding up to 100%. See here for an example.
more?Would you like to know
- Basic example
- Environment/shared config example
- Glob example
- Validating config files
- Forcing a preload/cache of YAML file(s)
- Flushing cached config
In most cases, you should not need to call flipr-yaml's methods directly, flipr takes care of that. However, it can be useful for testing and config validation.
async getConfig()- Returns yaml config as an object. The first call to this method caches the config, which can be cleared by calling the
async preload()- Loads the config into cache. Does the same thing as getConfig. It's called preload to fulfill flipr's source contract.
async flush()- Flushes all cached values in flipr-yaml.
async validateConfig(rules)- Validates the yaml files based on flipr's configuration syntax. See flipr-validation for more information.
filePath- required - string, array - The yaml config file path(s) relative to the process's cwd. Supports glob patterns based on minimatch patterns.
duplicateKeysOverride- bool - If true, duplicate keys in a multi-file scenario will be overridden by whichever is read last. Default is false, which results in an error thrown.