Skip to content
Snippets Groups Projects
Select Git revision
  • 80bf216c97bd565df9f51d903e1f732a1c4291d7
  • main default protected
  • 3-rewrite-in-typescript
  • 1.13.6
  • 1.13.5
  • 1.13.4
  • 1.13.3
  • 1.13.2
  • 1.13.1
  • 1.13.0
  • 1.12.4
  • 1.12.3
  • 1.12.2
  • 1.12.1
  • 1.12.0
  • 1.11.0
  • 1.10.1
  • 1.10.0
  • 1.9.0
  • v1.7.0
  • 1.8.0
  • v1.7.1
  • v1.6.2
23 results

config

  • Clone with SSH
  • Clone with HTTPS
  • Dominik Sigmund's avatar
    80bf216c
    History

    config

    Simple Config with ENV and Files Support.

    Installation

    • npm install --save @general/config

    Usage

    const Config = require('@general/config')
    let config = new Config([basePath])

    Then config is your config object. (Use it like config.setting)

    It reads from the following sources, performing a deep merge:
    (The Top Value overwrites the lower ones)

    • ENV
    • config.json
    • config.defaults.json

    Enviroment Variables can target deep nested settings:
    The Setting setting.deep.key can be reached with SETTING_DEEP_KEY

    You may use the function reload() to reload the config from all sources.
    `config.reload()``

    This makes reload a reserved keyword

    If you give a basePath, the config-Files are used from there.
    Else the main dir of the application will be used.

    Values

    You may use direct values like strings or numbers:

    {
      "key": "value"
    }

    You can also use files to read the value from. This makes the config compatible with e.g. secrets:

    {
      "key": "file:/path/to/file"
    }

    Examples

    Only config.defaults.json

    node examples/only-defaults/index.js

    Only config.json

    (Kind of legacy use)

    node examples/only-local/index.js

    defaults and config.json

    node examples/defaults-overwrite/index.js

    enviroment variables

    (Enviroment set by command to not pollute your machine)

    SETTING=overwritten-by-env node examples/env/index.js

    use files to read from

    (Enviroment set by command to not pollute your machine)

    SETTING=file:examples/files/setting_1.txt node examples/files/index.js