Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.28 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.28 KB

Config parsing

Node.js module for parsing configuration files with support of interpolating secrets.

Usage

Parsing a configuration file and secrets

You can use the following helper functions to read the configuration and secrets file from filesystem:

const rawConfig = loadConfig(join(__dirname, 'config.json'));
const rawSecrets = loadSecrets(join(__dirname, 'secrets.env'));

Creating the full configuration object

The module defines a interpolateSecretsIntoConfig function that takes a config object along with the secrets and returns the config with the secrets interpolated into it.

Examples:

// Basic interpolation
const rawConfig = {
  prop: 'value',
  secret: '${SECRET}',
};
const config = interpolateSecretsIntoConfig(rawConfig, { SECRET: 'secretValue' }); // { prop: 'value', secret: 'secretValue' }
// Allows escaping the interpolation syntax
const rawConfig = {
  prop: 'value',
  secret: '\\${SECRET}',
};
const config = interpolateSecretsIntoConfig(rawConfig, { SECRET: 'secretValue' }); // { prop: 'value', secret: '${SECRET}' }
// Throws an error if something is not right
const rawConfig = {
  prop: 'value',
  secret: '${SECRET}',
};
const config = interpolateSecretsIntoConfig(rawConfig); // Error: SECRET is not defined