UNPKG

3.08 kBMarkdownView Raw
1Project configuration, dataflows-style
2==========
3
4Goals
5----------
6
71. Easy to use
8Common format, you can set up a location of configuration files. If you already have one, you do not need to change files location for each project, you can just point this location (set up environment) for all needed projects.
9
102. Scalable
11Hierarchical, any section can live in a separate file, easy access to frequently changing sections.
12
133. Easy deployment
14Configuration actually is splitted to the project configuration and instance fixup. You can have as many fixups as you want, not only development and production.
15
164. Persistent
17Current configuration snapshot is always on disk and in vcs. No code allowed within configuration. Tools never change project config, only fixup allowed to change.
18
19Those is not acceptable:
20
211. `require ('config.json')` — 1, 2, 3;
222. nconf - 4 (require code to load includes)
233. node-convict - 2 (no access to frequently chnging sections), 3 (no separation beween project config and instance fixup)
244. dotenv - 2, 4 (recommended not to commit config)
255. node-config - 1 (cannot change location), 4 (instance name not stored on disk)
26
27Implementation
28---------------
29
30dataflows configuration is located within `.dataflows` directory in project root. Main configuration file named `project`, fixup directories located at same level as the `project` file.
31
321. `project` file is loaded and parsed. For now, only `json` format supported;
332. `project` contents is scanned against includes in form `"<include-file-name>"`;
343. when all includes is loaded, config tree is scanned for variables (`"<$config.path.variable>"`) and placeholders (`"<#please fix me>"`, `"<#optional:please fix me>"`, `"<#default:127.0.0.1>"`);
354. `fixup` file loaded and checked, whether all variables and placeholders fulfilled;
365. if resulting config is fulfilled, project emits `ready` event; otherwise, `error` event emitted.
37
38Caveats
39-----------
40
411. config format is guessed at launch
42most popular config formats (json and xml) can be parsed automatically (json can be detected by first chars - `{[`, xml must contains `<?xml version encoding?>`), another formats can have comment with format description on first line ("; ini")
43
442. Configuration must be separated from dataflows project and have no external dependencies.
45
46Environment variables to drive config (don't like it at all)
47------------
48PROJECT_ROOT absolute path
49PROJECT_CONF (relative to project root, dir name to search for "project" file)
50PROJECT_VAR (relative to project root, dir name to search for "instance" file)
51PROJECT_INSTANCE string
52techdebt: if PROJECT_ROOT is file path, then assume to load `project` config from that file and treat parent directory as project root.
53techdebt: if PROJECT_INSTANCE is file path, then assume to load `fixup` contents from that file.
54
55
56Links
57---------------
58http://thejeffchao.com/blog/2013/09/26/an-alternative-node-dot-js-configuration-management-pattern/
59http://metaduck.com/03-konphyg.html
60https://github.com/mozilla/node-convict
61https://github.com/scottmotte/dotenv