Created
August 2, 2020 08:33
-
-
Save qrg/4f2f3af88bd81f20ea8e0f2801ed0e26 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
const { ENV_VAR_1, ENV_VAR_2, ENV_VAR_3 } = process.env; | |
const filterUndefinedVars = (vars: { | |
[variableName: string]: any; | |
}): string[] => { | |
return Object.entries(vars) | |
.filter(([_k, v]) => typeof v === 'undefined') | |
.map(([variableName]) => variableName); | |
}; | |
const undefinedVars = filterUndefinedVars({ | |
ENV_VAR_1, | |
ENV_VAR_2, | |
ENV_VAR_3 | |
}); | |
if (undefinedVars.length >= 1) { | |
undefinedVars.forEach((varName) => { | |
console.error(`An environment variable ${varName} is not set.`); | |
}); | |
throw new Error('One or more required environment variables are missing.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment