Skip to content

Commit

Permalink
Add environment variable check.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZandercraftGames committed Sep 29, 2023
1 parent c2e480b commit 6696b43
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
*/
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.
Expand Down

0 comments on commit 6696b43

Please sign in to comment.