0.7.10 • Published 4 months ago

@bleco/config v0.7.10

Weekly downloads
-
License
MIT
Repository
-
Last release
4 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.10

4 months ago

0.7.9

5 months ago

0.7.8

5 months ago

0.6.7

10 months ago

0.6.9

10 months ago

0.6.8

10 months ago

0.6.10

9 months ago

0.6.12

9 months ago

0.6.11

9 months ago

0.6.13

9 months ago

0.7.2

8 months ago

0.7.1

8 months ago

0.7.4

8 months ago

0.7.3

8 months ago

0.7.0

9 months ago

0.7.6

7 months ago

0.7.5

7 months ago

0.7.7

6 months ago

0.6.6

11 months ago

0.6.3

11 months ago

0.6.2

11 months ago

0.6.5

11 months ago

0.6.4

11 months ago

0.6.1

11 months ago

0.6.0

11 months ago

0.5.4

12 months ago

0.5.3

12 months ago

0.5.6

11 months ago

0.5.5

12 months ago

0.5.0

1 year ago

0.5.2

12 months ago

0.5.1

12 months ago

0.4.15

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.10

1 year ago

0.4.13

1 year ago

0.4.14

1 year ago

0.4.11

1 year ago

0.4.12

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.3.31

1 year ago

0.3.30

1 year ago

0.3.33

1 year ago

0.3.32

1 year ago

0.3.29

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

1 year ago

0.3.23

2 years ago

0.3.22

2 years ago

0.3.9

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.20

2 years ago

0.3.21

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.0

2 years ago

0.2.6

2 years ago

0.3.2

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago