API
config.load(options?)
Loads .env and xpulse.json, merges defaults and resolves ${VAR}.
Emits config:loaded after successful load.
| 1 | await config.load(); |
| 2 | await config.load({ path: '/app', env: 'stage' }); |
| Option |
Type |
Description |
path |
string |
Directory containing xpulse.json β default: process.cwd() |
env |
string |
Environment for .env.{env} β fallback: process.env.NODE_ENV |
Errors:
| Situation |
Behaviour |
xpulse.json not found |
throws Error |
| Invalid JSON |
throws Error |
name missing |
throws Error |
| Unknown keys |
ignored, no warning |
${VAR} unresolvable |
warning, value stays ${VAR} |
config.get(path, fallback?)
Returns a value from the configuration. Supports dot notation.
| 1 | config.get('http.port') |
| 2 | config.get('i18n.locales') |
| 3 | config.get('sources.chat.url') |
| 4 | config.get('release.current') |
| 5 | config.get('missing.key', 'default') |
| 6 | config.get('missing.key') |
| Parameter |
Type |
Description |
path |
string |
Dot-notation path |
fallback |
unknown |
Returned if path does not exist (default: null) |
config.all()
Returns all configuration values β including defaults and resolved ${VAR}.
Returns a copy, not a reference.
| 1 | const all = config.all(); |
| 2 | |
config.name
Shorthand for config.get('name').
config.type
Shorthand for config.get('type').
config.loaded
true after a successful load().
Event: `config:loaded`
Emitted after load().
| 1 | |
| 2 | { |
| 3 | name: 'xpulse-web', |
| 4 | type: 'tool', |
| 5 | env: 'production', |
| 6 | files: [ |
| 7 | '/app/xpulse.json', |
| 8 | '/app/.env', |
| 9 | '/app/.env.production', |
| 10 | ] |
| 11 | } |