Node.js module for parsing configuration files with support of interpolating 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'));
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