Last active
July 26, 2018 09:09
-
-
Save joseluisq/c156d6fb268a1685e810ea2b474035d6 to your computer and use it in GitHub Desktop.
Environment variables validator
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
const env = (key) => process.env[key] || null | |
const debug = (obj) => console.dir(obj, { colors: true }) | |
const validator = (vlist = []) => { | |
const errors = [] | |
vlist.forEach(v => { | |
if (!env(v)) errors.push(`No '${v}' supplied!`, v) | |
}) | |
return { | |
valid: () => !!!errors.length, | |
errors: () => { | |
console.log('ERRORS:') | |
errors.forEach(error => console.log(` - ${error}`)) | |
process.exit(1) | |
} | |
} | |
} | |
module.exports = { | |
env, | |
debug, | |
validator | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: