Porque nao fazer mais simples?
function checkEnvVariables(variables) {
for (const variable of variables) {
if (!process.env[variable]) {
console.error('missing: ', variable)
}
}
}
const requiredEnvVariables = ['DATABASE_URL', 'API_KEY', 'SECRET_KEY'];
checkEnvVariables(requiredEnvVariables)