@rotty3000/config-node 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +27 -10
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @rotty3000/config-node
2
2
  A library for obtaining external configuration for your application.
3
3
 
4
+ This library lets you externalize the configuration of your application so that it can work without any changes in different environments. You use JSON files, environment variables, command line arguments or other well known sources like [Volume Mounted Kubernetes ConfigMaps (or Secrets)](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume) to deliver configuration to your application without changing a single line. Property values can be looked up anywhere in your code by using the `lookupConfig` function.
5
+
6
+ Optionally [custom providers](#custom-providers) can be added to search more exotic sources of configuration like a database, key/value store or secrets vault.
7
+
4
8
  ## Usage
5
9
 
6
10
  ```typescript
@@ -17,12 +21,12 @@ defaultConfig('config.node.config.trees', ['/configtree']);
17
21
 
18
22
  ## Sources of Configuration
19
23
 
20
- The following configuration sources are used in order of precedence.
24
+ The following configuration providers are pre-packaged and searched in order of precedence until a value is found.
21
25
 
22
- 1. A JSON file `~/.config-node-devtools.json` in the user home directory which contains configuration keys (following example above `{"a.configuration.key": {"some.value": "foo"}`)
26
+ 1. A JSON file `~/.config-node-devtools.json` in the user home directory which contains configuration keys. (See [Structure of JSON configuration](#structure-of-json-configuration).)
23
27
  1. Command line arguments formatted as `--key=value`.
24
- 1. From command line argument `--application.json=<json>` where the inline JSON is structured as in 1.
25
- 1. Properties from the `APPLICATION_JSON` environment variable whose value is inline JSON
28
+ 1. From command line argument `--application.json=<json>` where the inline JSON is structured as in 1. (See [Structure of JSON configuration](#structure-of-json-configuration).)
29
+ 1. Properties from the `APPLICATION_JSON` environment variable whose value is inline JSON. (See [Structure of JSON configuration](#structure-of-json-configuration).)
26
30
  1. From individual environment variables (following name mangling rules):
27
31
  * Replace dots (.) with underscores (_).
28
32
  * Remove any dashes (-).
@@ -40,11 +44,11 @@ The following configuration sources are used in order of precedence.
40
44
  _e.g._
41
45
 
42
46
  Given a Kubernetes ConfigMap or Secret mounted at `/config-map` with a data file located at `/config-map/a.config.map.key`, looking up the property `a.config.map.key` will return the contents of the file as the value.
43
- 1. From application profile property json files in `${CWD}/config/application-{profile}.json` where _profile_ is set using the property `config.node.profiles.active` (using any of the sources described in this list, for instance as an environment variable `CONFIG_NODE_PROFILES_ACTIVE=test`).
44
- 1. From application profile property json files in `${CWD}/application-{profile}.json` where _profile_ is set using the property `config.node.profiles.active` (using any of the sources described in this list, for instance as an environment variable `CONFIG_NODE_PROFILES_ACTIVE=test`).
45
- 1. From application property json files in `${CWD}/config/application.json`.
46
- 1. From application property json files in `${CWD}/application.json`.
47
- 1. From application property json files packaged with the node.js app (i.e. adjacent to the main script).
47
+ 1. From application profile property json files in `${CWD}/config/application-{profile}.json` where _profile_ is set using the property `config.node.profiles.active` (using any of the sources described in this list, for instance as an environment variable `CONFIG_NODE_PROFILES_ACTIVE=test`). (See [Structure of JSON configuration](#structure-of-json-configuration).)
48
+ 1. From application profile property json files in `${CWD}/application-{profile}.json` where _profile_ is set using the property `config.node.profiles.active` (using any of the sources described in this list, for instance as an environment variable `CONFIG_NODE_PROFILES_ACTIVE=test`). (See [Structure of JSON configuration](#structure-of-json-configuration).)
49
+ 1. From application property json files in `${CWD}/config/application.json`. (See [Structure of JSON configuration](#structure-of-json-configuration).)
50
+ 1. From application property json files in `${CWD}/application.json`. (See [Structure of JSON configuration](#structure-of-json-configuration).)
51
+ 1. From application property json files packaged with the node.js app (i.e. adjacent to the main script). (See [Structure of JSON configuration](#structure-of-json-configuration).)
48
52
  1. From programer provided defaults. As demonstrated in the sample code above a developer can pre-set values to act as the defaults when no other source provides a value.
49
53
 
50
54
  e.g.
@@ -52,6 +56,19 @@ The following configuration sources are used in order of precedence.
52
56
  defaultConfig('my.custom.config', 'some value');
53
57
  ```
54
58
 
59
+ ## Structure of JSON configuration
60
+
61
+ The configuration JSON structure expects keys to be at the root, as follows:
62
+
63
+ ```json
64
+ {
65
+ "key.with.array.value": ["one", "two"],
66
+ "key.with.object.value": {"some.value": "foo"},
67
+ "key.with.number.value": 5,
68
+ "key.with.string.value": "dev",
69
+ }
70
+ ```
71
+
55
72
  ## Custom Providers
56
73
 
57
74
  Custom providers can be added as middle ware to without affecting other parts of the code.
@@ -60,7 +77,7 @@ Custom providers can be added as middle ware to without affecting other parts of
60
77
  import {addProvider, computeIfAbsent, ConfigProvider} from '@rotty3000/config-node';
61
78
 
62
79
  const customProvider: ConfigProvider = {
63
- description: "From a database, vault or whatever",
80
+ description: "From a database, key value store or secrets vault",
64
81
  priority: 100,
65
82
  get: (key, providerCache, commonCache) => {
66
83
  // If the work is hard, put the value in providerCache for better performance over repeat get operations.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@rotty3000/config-node",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "A library for obtaining external configuration for your application.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "clean": "rm -rf dist",
9
- "prepublish": "tsc",
9
+ "prepublish": "npm run clean && tsc",
10
10
  "build": "tsc",
11
11
  "run": "npm run clean && npm run build && node dist/src/index.js",
12
12
  "test": "npm run clean && npm run build && ts-mocha test/*.ts"