31 lines
620 B
JavaScript
31 lines
620 B
JavaScript
global.PWD = process.env.NODE_PWD || process.cwd()
|
|
|
|
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',
|
|
}
|
|
|
|
export default {
|
|
...readFromEnv(['NODE_ENV', 'POSTGRES_HOST'], defaults),
|
|
}
|