Class: ConfigurationProperties

node/configuration-properties.ConfigurationProperties(defaultProperties, prefix, fs)

Reads the configuration from file and environment variables.

The configuration is read from a JSON file application.json from the working directory. Can be configured with config.name, config.location.

Example:

const configuration = ConfigurationProperties.create();
const config = await configuration.get();

With default values:

const configuration = ConfigurationProperties.create({
  defaultProperties: {
      port: 8080,
      database: { host: 'localhost', port: 5432 },
  },
});
const config = await configuration.get();

Constructor

new ConfigurationProperties(defaultProperties, prefix, fs)

The constructor is for internal use. Use the factory methods instead.

Parameters:
Name Type Description
defaultProperties T
prefix string
fs fsPromises
See:
  • ConfigurationProperties.create
  • ConfigurationProperties.createNull

Methods

(async) get() → {Promise.<T>}

Loads the configuration from the file.

Returns:

The configuration object.

Type
Promise.<T>

(static) create(options) → {ConfigurationProperties.<T>}

Creates an instance of the application configuration.

Parameters:
Name Type Description
options object

The configuration options.

Properties
Name Type Attributes Default Description
defaultProperties T <optional>
null

The default configuration.

prefix string <optional>
""

The prefix of the properties to get.

Returns:

The new instance.

Type
ConfigurationProperties.<T>

(static) createNull(options) → {ConfigurationProperties.<T>}

Creates a nullable of the application configuration.

Parameters:
Name Type Description
options object

The configuration options.

Properties
Name Type Attributes Default Description
defaultProperties T <optional>
null

The default configuration.

prefix string <optional>
""

The prefix of the properties to get.

files object <optional>
{}

The files and file content that are available.

Returns:

The new instance.

Type
ConfigurationProperties.<T>