Last active
August 21, 2019 15:38
-
-
Save jerolan/a8531134279dd279a823c7748a75e0b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const customEnv = require('custom-env'); | |
const NODE_ENV = process.env.NODE_ENV || 'development'; | |
/** | |
* Shares behaviour with CRA for envs | |
* https://create-react-app.dev/docs/adding-custom-environment-variables#what-other-env-files-can-be-used | |
**/ | |
customEnv.env(); | |
customEnv.env('local'); | |
customEnv.env(NODE_ENV); | |
customEnv.env(`${NODE_ENV}.local`); | |
const { MY_ENV_VAR } = process.env; | |
const defaults = { MY_ENV_VAR: null }; | |
// Alert to fill the necessary environment variables | |
Object.keys(defaults).forEach(key => { | |
if (!process.env[key]) { | |
throw new Error( | |
`Please enter a custom ${key} in .env.${NODE_ENV} on the root directory` | |
); | |
} | |
}); | |
module.exports = { | |
NODE_ENV, | |
MY_ENV_VAR, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment