API
config.load(options?)
Lädt .env und xpulse.json, merged Fallbacks und löst ${VAR} auf.
Feuert config:loaded nach erfolgreichem Laden.
| 1 | await config.load(); |
| 2 | await config.load({ path: '/app', env: 'stage' }); |
| Option |
Typ |
Beschreibung |
path |
string |
Verzeichnis mit xpulse.json – Standard: process.cwd() |
env |
string |
Environment für .env.{env} – Fallback: process.env.NODE_ENV |
Fehler:
| Situation |
Verhalten |
xpulse.json nicht gefunden |
wirft Error |
| Ungültiges JSON |
wirft Error |
name fehlt |
wirft Error |
| Unbekannte Keys |
ignoriert, keine Warnung |
${VAR} nicht auflösbar |
Warnung, Wert bleibt ${VAR} |
config.get(path, fallback?)
Gibt einen Wert aus der Konfiguration zurück. Unterstützt 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 |
Typ |
Beschreibung |
path |
string |
Dot-Notation Pfad |
fallback |
unknown |
Rückgabe wenn Pfad nicht existiert (Standard: null) |
config.all()
Gibt alle Konfigurationswerte zurück – inkl. Fallbacks und aufgelösten ${VAR}.
Gibt eine Kopie zurück, keine Referenz.
| 1 | const all = config.all(); |
| 2 | |
config.name
Kurzform für config.get('name').
config.type
Kurzform für config.get('type').
config.loaded
true nach erfolgreichem load().
Event: `config:loaded`
Wird nach load() emittiert.
| 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 | } |