Skip to content

Instantly share code, notes, and snippets.

@romanonthego
Created May 25, 2018 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanonthego/16791dac753c2c7d4fcbbdeec6eed29b to your computer and use it in GitHub Desktop.
Save romanonthego/16791dac753c2c7d4fcbbdeec6eed29b to your computer and use it in GitHub Desktop.
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