-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkEnvVar.js
56 lines (50 loc) · 1.25 KB
/
checkEnvVar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Check for all the required environment variables in production
const checkEnv4Production = () => {
// All required environment variables in
const requiredEnvVars = [
"PORT",
"MONGO_URI",
"JWT_PRIVATE_KEY",
"SENDER_EMAIL_ID",
"EMAIL_PASSWORD",
"CLIENT_URL",
];
// filter missing environment variables
const missingEnvVars = requiredEnvVars.filter(
(varName) => !process.env[varName]
);
if (missingEnvVars.length > 0) {
console.log(`Missing environment variables: ${missingEnvVars.join(", ")}`);
process.exit(1);
} else {
console.log(
"Great! All required environment variables for production are present"
);
}
return;
};
const checkEnv4Development = () => {
const requiredEnvVars = [
"PORT",
"MONGO_URI",
"JWT_PRIVATE_KEY",
"NODE_ENV",
"CLIENT_URL",
];
const missingEnvVars = requiredEnvVars.filter(
(varName) => !process.env[varName]
);
if (missingEnvVars.length > 0) {
console.log(`Missing environment variables: ${missingEnvVars.join(", ")}`);
process.exit(1);
} else {
console.log(
"Great! All required environment variables for development are present"
);
}
return;
};
module.exports = {
checkEnv4Production,
checkEnv4Development,
};