Global

Methods

generate(obj) → {object}

Generates an object suitable for use with config's config/custom-environment-variables.json, skipping any functions encountered in the given object. Example:

  const fs = require('fs');
  const config = require('config');
  const cev = require('config-custom-environment-variables-generator');
  fs.writeFileSync('config/custom-environment-variables.json', JSON.stringify(cev.generate(config, { prefix: 'MYAPP' }), null, 2)));
Parameters:
Name Type Attributes Default Description
obj object

An object, most likely the one returned by require('config').

opts.prefix string <optional>
'NODE_APP'

Prefix to use on environment variables. Use @ to use the name of your application (see exported DEFAULT_PREFIX).

opts.noPrefix boolean <optional>
false

Overrides use of any prefix (see exported DEFAULT_NO_PREFIX).

opts.separator separator <optional>
'_'

The word separator in environment variables (see exported DEFAULT_SEPARATOR).

opts.casing 'upper' | 'lower' | undefined <optional>
'upper'

The case to use. upper forces upper case, lower forces lower case, else case is unchanged (see exported DEFAULT_CASING, CASING_UPPER, CASING_LOWER, and CASING_UNCHANGED).

opts.empties boolean <optional>
false

If true, preserves empty objects that didn't have any environment variables, else skips entries that wouldn't have any environment variables (functions are always skipped).

opts.formats object <optional>
{}

If given, must be an object that specifies the __format value for the corresponding key of the first argument,

Source:
Returns:

An object containing the generated environment variables for each key in the input object.

Type
object

generate(obj) → {object}

Generates an object suitable for use with config's config/custom-environment-variables.json, skipping any functions encountered in the given object. Example:

  const fs = require('fs');
  const config = require('config');
  const cev = require('config-custom-environment-variables-generator');
  fs.writeFileSync('config/custom-environment-variables.json', JSON.stringify(cev.generate(config, { prefix: 'MYAPP' }), null, 2)));
Parameters:
Name Type Attributes Default Description
obj object

An object, most likely the one returned by require('config').

opts.prefix string <optional>
'NODE_APP'

Prefix to use on environment variables. Use @ to use the name of your application (see exported DEFAULT_PREFIX).

opts.noPrefix boolean <optional>
false

Overrides use of any prefix (see exported DEFAULT_NO_PREFIX).

opts.separator separator <optional>
'_'

The word separator in environment variables (see exported DEFAULT_SEPARATOR).

opts.casing 'upper' | 'lower' | undefined <optional>
'upper'

The case to use. upper forces upper case, lower forces lower case, else case is unchanged (see exported DEFAULT_CASING, CASING_UPPER, CASING_LOWER, and CASING_UNCHANGED).

opts.empties boolean <optional>
false

If true, preserves empty objects that didn't have any environment variables, else skips entries that wouldn't have any environment variables (functions are always skipped).

opts.formats object <optional>
{}

If given, must be an object that specifies the __format value for the corresponding key of the first argument,

Source:
Returns:

An object containing the generated environment variables for each key in the input object.

Type
object