journey/server/config/env.js
Linus Miller 6048991b2d new config loading logic
- remove unused config files
- load all server env variables from ./config/env
- still define PWD as midwest seems to be using it
2020-08-28 20:48:22 +02:00

31 lines
584 B
JavaScript

'use strict'
function readFromEnv(columns, defaults) {
const missing = []
const result = columns.reduce((result, variable) => {
const value = (result[variable] = process.env[variable] || defaults[variable])
if (!value) {
missing.push(variable)
}
return result
}, {})
if (missing.length) {
throw new Error(`Missing required env variables: ${missing.join(', ')}`)
}
return result
}
const defaults = {
NODE_ENV: 'development',
POSTGRES_HOST: 'localhost',
}
module.exports = {
...readFromEnv(['NODE_ENV', 'POSTGRES_HOST'], defaults),
}