Add environment variable check.

This commit is contained in:
2023-09-29 12:21:59 -04:00
parent c2e480bb4b
commit 6696b43fdc

21
bin/www
View File

@@ -5,6 +5,27 @@
*/ */
require('dotenv').config() require('dotenv').config()
// Check if the .env config file is included.
const required_variables = [
process.env.MONGODB_CONN_STRING,
process.env.ADMIN_USER,
process.env.ADMIN_PASS,
process.env.NAME,
process.env.HOST,
process.env.API_KEY
]
for (let variable of required_variables) {
if (variable === undefined) {
console.error("ERROR: Configuration error! You are either missing a .env file or have not properly configured all " +
"required environment variables.\n" +
"Depending on your environment, this may require copying .env.example to .env and modifying the configuration " +
"file or defining the missing environment variables (see the .env.example file)." +
"\nExiting...")
process.exit(1)
}
}
/** /**
* Module dependencies. * Module dependencies.