fp-common v4.2.10
npm-fp-common
NPM package with common NodeJS application functionalities like configuration parsing, logging and more
Config
Inspired by Symfony configuration component syntax with support of JSON and YAML files with possibility to mix them both. Library supports imports and parameters
Parameters
Stored in reserved top-level parameters configuration attribute, Every configuration file
can include it's own parameters.
To inject parameter value into the configuration strings surround it's name by % character.
To escape reserved % character use another %, e.g. %% will be compiled as single %.
Imports
To import specific file, include it in array stored in reserved imports attribute, with path
relative to configured root path (see: example).
Example
Let's imagine you have a config /app/config/config.json and it's env-based additions,
plus security configs and you need to merge all of them.
- app
--- config
..... config.json
..... config.test.json
..... config.prod.json
----- security
....... firewall.test.yml
....... firewall.prod.yml
- src
... app.tsconfig.json
{
"env": "%env%",
"firewall": {
"enabled": "%is_firewall_enabled%"
},
"logger": {
"output": "syslog"
}
}config.test.json
{
"imports": [
"config.json",
"security/firewall.test.yml"
],
"parameters": {
"env": "test"
},
"logger": {
"output": "console"
}
}security/firewall.test.yml
parameters:
is_firewall_enabled: trueapp.ts
import {Config} from "fp-common";
let configLoader = new ConfigLoader("../../app/config/");
console.log(configLoader.load("config." + process.env + ".json"));output with ENV=test:
{
"env": "test",
"firewall": {
"enabled": true
},
"logger": {
"output": "console"
}
}