0.7.11 • Published 9 months ago

@bleco/config v0.7.11

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

@bleco/config

LoopBack

A loopback-next configuration loading utility

Features

Usage

demo.config.yaml

name: hello
foo:
  bar:
    a: ${FOO_BAR_A}
    b: ${FOO_BAR_B}
    c: ${FOO_BAR_C}
    d: ${FOO_BAR_D}
deep:
  object:
    property: value

.env.default

FOO_BAR_A=foo_bar_1
FOO_BAR_B=foo_bar_2

.env

FOO_BAR_A=foo_bar_3
FOO_BAR_C=foo_bar_4
import {load} from '@bleco/config';

// load config from directory and merge environments with `read-env`
const config = await load('demo', '<dir>');
// or leave arg empty and run in `<dir>`
// const config = await load('demo');

console.log(config);

//=>
//{
//  "name": "hello",
//  "foo": {
//    "bar": {
//      "a": "foo_bar_3",
//      "b": "foo_bar_2",
//      "c": "foo_bar_4",
//      "d": "${FOO_BAR_D}"
//    }
//  },
//  "deep": {
//    "object": {
//      "property": "value"
//    }
//  }
//}

.env.* files

You can have the following .env* files in your project:

  • .env.default – for default (fallback) values, tracked by VCS
  • .env – for default production values, tracked by VCS
  • .env.development – for development environment, tracked by VCS
  • .env.test – for test environment, tracked by VCS
  • .env.production – for production environment, tracked by VCS
  • .env.local – for individual default values, ignored by VCS
  • .env.development.local – for individual development environment values, ignored by VCS
  • .env.test.local – for individual test environment values, ignored by VCS
  • .env.production.local – for production environment values (DB passwords, API keys, etc.), ignored by VCS

config files

File patterns

Config files are grouped into either the root or branch category. The root of a project is denoted by a root *.config.* file, or a folder with the name .config, which contains config files. Branch config files are located within folders (at any depth) below the root, and are prefixed with a leading dot (.).

RootBranch
.config/<name>.<ext>, <name>.config.<ext>.<name>.<ext>
.config/<name>.<env>.<ext>, <name>.config.<env>.<ext>.<name>.<env>.<ext>
  • <name> - Name passed to your Configuration instance (in camel case).
  • <env> - Current environment derived from NODE_ENV.
  • <ext> - File extension supported by the defined loaders and extensions.

Lookup resolution

When the finder traverses through the file system and attempts to resolve config files within each/target folder, it does so using the lookup algorithm demonstrated below. Let's assume the following:

  • The config file name is app.
  • All file formats are supported, in their default lookup order (js, json, cjs, mjs, ts, json5, yaml, yml).
  • The current environment is development (the value of NODE_ENV).
app.js
app.development.js
app.json
app.development.json
app.cjs
app.development.cjs
app.mjs
app.development.mjs
app.ts
app.development.ts
app.json5
app.development.json5
app.yaml
app.development.yaml
app.yml
app.development.yml

Roadmap

License

MIT

0.7.11

9 months ago

0.7.10

1 year ago

0.7.9

2 years ago

0.7.8

2 years ago

0.6.7

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.10

2 years ago

0.6.12

2 years ago

0.6.11

2 years ago

0.6.13

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.7

2 years ago

0.6.6

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.15

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.10

2 years ago

0.4.13

2 years ago

0.4.14

2 years ago

0.4.11

2 years ago

0.4.12

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.31

2 years ago

0.3.30

2 years ago

0.3.33

2 years ago

0.3.32

2 years ago

0.3.29

2 years ago

0.3.28

2 years ago

0.3.27

2 years ago

0.3.26

2 years ago

0.3.25

2 years ago

0.3.24

3 years ago

0.3.23

3 years ago

0.3.22

3 years ago

0.3.9

3 years ago

0.3.17

3 years ago

0.3.16

3 years ago

0.3.15

3 years ago

0.3.14

3 years ago

0.3.13

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.10

3 years ago

0.3.20

3 years ago

0.3.21

3 years ago

0.3.19

3 years ago

0.3.18

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.2.6

3 years ago

0.3.2

3 years ago

0.2.3

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago