1
0
Fork 0
nodejs-backend-template/server/utils/check-dotenv.js

21 lines
485 B
JavaScript

/**
* @module Checks for required environment variables and terminates the process if they are missing.
*/
const dotenvVariables = [
'NODE_ENV',
'PORT',
'SERVICE_NAME'
];
const missingDotenvVariables = [];
dotenvVariables.forEach(variable => {
if (!process.env[variable]) {
missingDotenvVariables.push(`${variable}`);
}
});
if (missingDotenvVariables.length) {
console.error(`Following dotenv variables are missing: ${missingDotenvVariables}`);
process.exit(-1);
}