Configuration Class
Configurations load in 2 stages.
The first stage is a blocking file read to provide base data for the application and base configurations as described by the system.
The second stage is to load data from extended data sources in a non-blocking fashion. A _await
property is provided as a Promise to allow for waiting for the full configuration load if desired.
Note that as this extends an EventEmitter, colliding key names should be avoided, such as "on" and
"once". Due to the nature of the EventEmitter properties and for simplicity, Configuration merely
extends the EventEmitter class so that configuration.on
and similar methods are simply available
without needing to remember referencing such as configuration._events.on
, however the extended
event emitted is also available as _events to allow for key collision if needed.
Additionally, this module binds a listener to the "SIGHUP" Process Event to trigger configuration reload events.
Item Index
Methods
Methods
_reload
()
Promise
Update the configurations.
This will cause all configuration sources to be read again and then applied over the current configuration. Which will change values that exist but will in general not delete values.
Specifically this will not remove values at the first, or second level due to the way in which the configurations are assembled. Keys at the third level or deeper will fall off IF the second level key has an update applied.
Returns:
Resolves with the final status of the configuration loading; See: "loaded" and "error" events.
getExt
-
path
Parameters:
-
path
StringFile name or complete file path.
Returns:
initialized.failure
-
exception
Called if the first completion of the second load stage resulted in an exception.
Parameters:
-
exception
ErrorThe thrown exception
initialized.success
()
private
Called after the first completion of the second load stage.
isLocked
()
Boolean
private
Indicate if the configuration module is currently updating.
This currently responds to the following states:
- reloading
Returns:
loadConfigurations
()
private
loadFailed
-
exception
Parameters:
-
exception
Error
Returns:
loadFailed
-
exception
Parameters:
-
exception
Error
Returns:
loadFile
-
file
Parameters:
-
file
StringFilename to load.
readJSON
-
path
Parameters:
-
path
String
Returns:
resolveConfiguration
-
conf
Parameters:
-
conf
ObjectConfiguration to resolve against the current export.
Properties
_await
Promise
Called after the first completion of the second load stage.
_emitter
EventEmitter
Provides a reference to the extended event emitter to allow for key collisions off of the configuration object itself.
_events
Object
private
Maps event names to their current name for consistency.
loaded
Object
private
Tracks included javascript file configurations so that reloads can be triggered via their functional invocations.
reloading
Boolean
private
When true, the configuration is updating its values. This does not block the values from being used, but does indicate that the module is busy and operations that would cause further updates should be blocked.
Events
failed
Thrown in the case of an error in any stage.
Event Payload:
-
conf
ConfigurationThis configuration that finished loading.
-
error
ErrorThrown exception