Load configuration from environmental variables and files.
According to The Twelve-Factor App, configuration should come from environmental variables. But since environmental variables can leak easily, some people use secrets for sensitive information. This module is made to support either with minimal set-up.
npm install env-and-files
Or, with yarn
:
$ yarn add env-and-files
const {loadConfig} = require('env-and-files');
loadConfig({
postgresPassword: {
filePath: '/secrets/password',
},
postgresUrl: {
format: (value) => new URL(value),
variableName: 'POSTGRES_URL',
},
postgresUsername: {
defaultValue: 'postgres',
filePath: '/secrets/username',
},
})
.then((config) => {
// "config" will be an object map of configuration properties.
console.log(config);
})
.catch((error) => {
// If any of the required properties cannot be loaded, the Promise will reject.
console.error(error);
});
Load configuration. Returns a Promise
that will resolve to the loaded configuration, or reject if the configuration was invalid.
Type: Object
An object map of configuration and where to find it. By default, all configuration properties are required. See usage for examples of config maps.
Load configuration, synchronously. Returns the loaded configuration, or throws if the configuration was invalid.
Type: Object
Same as the asynchronous version.
MIT © Matthew Fernando Garcia