-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# values : drv| prod | ||
APP_ENV = | ||
|
||
# local : 3000 | ||
PORT = | ||
|
||
# local : mongodb://127.0.0.1:27017 | ||
DB_URL = | ||
DB_NAME = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
todo.txt | ||
node_modules | ||
.env | ||
.env.dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const dotenv = require('dotenv'); | ||
const path = require('path'); | ||
const { env } = require('node:process'); | ||
|
||
/** | ||
* ! define mandatory environment variables inside the envVars array | ||
*/ | ||
const envVars = ['PORT']; | ||
|
||
dotenv.config(); | ||
const ENV_BASE_PATH = path.join(__dirname, '..', `.env.${env.APP_ENV}`); | ||
dotenv.config({ | ||
path: ENV_BASE_PATH, | ||
}); | ||
|
||
function isEnvVarExits(envVars) { | ||
return new Promise((res, rej) => { | ||
let notDefinedEnvVars = envVars.filter((envVar) => !env[envVar]); | ||
if (notDefinedEnvVars.length > 0) | ||
throw { | ||
code: 500, | ||
error: { | ||
message: `following env vars are not defined:\n ${notDefinedEnvVars.join( | ||
', ', | ||
)}`, | ||
}, | ||
}; | ||
return res(); | ||
}); | ||
} | ||
|
||
async function runEnv(envVars) { | ||
try { | ||
let result = await isEnvVarExits(envVars); | ||
} catch (error) { | ||
process.exit(1); | ||
} | ||
} | ||
|
||
runEnv(envVars); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters