Created
May 25, 2018 11:24
-
-
Save romanonthego/16791dac753c2c7d4fcbbdeec6eed29b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import 'colors' | |
const validAppEnvs = ['development', 'staging', 'production'] | |
let APP_ENV = process.env.APP_ENV | |
if (!APP_ENV) { | |
console.log( | |
'The APP_ENV environment variable is required but was not specified.' | |
.yellow, | |
'"development" will be used as default'.yellow, | |
) | |
APP_ENV = 'development' | |
} | |
if (!validAppEnvs.includes(APP_ENV)) { | |
console.log( | |
`The APP_ENV environment variable is invalid.`.yellow, | |
`One of${JSON.stringify(validAppEnvs)} required`.yellow, | |
'"development" will be used as default'.yellow, | |
) | |
APP_ENV = 'development' | |
} | |
export default function getEnvVariables(__DIR) { | |
const dotenvFiles = [ | |
path.join(__DIR, `.env.${APP_ENV}`), | |
path.join(__DIR, '.env'), | |
] | |
dotenvFiles.forEach(dotenvFile => { | |
require('dotenv').config({path: dotenvFile}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment