开发者社区> 镜像站> NPM> fp-common
fp-common
NPM package with common interfaces for Jumia Food npm packages.
Last updated 5 months ago by faianca .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fp-common 
SYNC missed versions from official npm registry.

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.ts

config.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: true

app.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"
    }
}

Current Tags

  • 4.2.10                                ...           latest (5 months ago)

2 Versions

  • 4.2.10                                ...           5 months ago
  • 4.2.9                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (13)
Dev Dependencies (15)
Dependents (0)
None