Internal object that stores default environment values as a key in the underlying object. Environmental variables must be registered in this object before retrieval.
Validates that an environment key is registered and optionally is a certain type.
The key to validate internally.
A string to do a typeof
compare.
Gets the numeric value of an environmental variable.
Environment.register("SOME_KEY", 5);
// Logs the numeric value of process.env["SOME_KEY"] if it is set and is a number.
// otherwise the number 5 will be logged.
console.log(Environment.getNumber("SOME_KEY"));
The environment key to retrieve.
The numeric value of the environment variable.
Gets the string value of an environmental variable.
Environment.register("SOME_KEY", "THIS IS A TEST");
// Logs the numeric value of process.env["SOME_KEY"] if it is set.
// otherwise "THIS IS A TEST" will be logged.
console.log(Environment.getNumber("SOME_KEY"));
The environment key to retrieve.
The string value of the environment variable.
Gets the string value of an environment variable.
When called, this method will search for key
in the environment. If
a value was found, it will be returned from process.env[key]
. When no
value was found for key
, the value that was specified in the second
paramter of register will be returned.
An environment variable must be first registered through the register method. Any attempts to access a non-registered variable will lead to a NotRegisteredError.
Environment.register("SOME_KEY", "TEST");
// Logs the value of process.env["SOME_KEY"] if it exists
// Logs "TEST" otherwise.
console.log(Environment.getValue("SOME_KEY"));
The environment key to retrieve.
The validation scheme to use.
The string value of the environment variable.
Registers an environmental variable to the application.
Prior to any getValue
method calls, an environmental must be registered
to the application with a default value. The default value will ensure
that type checking happens on the typed methods and that a valid value
is always returned by those methods in the absence of the environment key.
Environment
.register("A", 5)
.register("B", "Hello")
.register("C", "World")
// The environmental variables process.env.A, process.env.B, process.env.C
// are now registered in the application with defaults of 5, "Hello" and "World"
// respectively.
The key to register.
The default value that is returned when not present in the environment.
A reference to the class for method chaining.
Generated using TypeDoc
Manages environmental variables needed by the application. It should be noted that while this class is not exported, a singleton object is exported via Environment.