add env var checking
This commit is contained in:
parent
001cce5374
commit
ece8da877a
|
|
@ -1,2 +1,4 @@
|
|||
DATABASE_URL='<database_url>'
|
||||
SECRET_KEY='<secret_key>'
|
||||
DB_URL='<database_url>'
|
||||
JWT_SECRET='<secret_key>'
|
||||
JWT_EXPIRES_IN='1d'
|
||||
PORT=5000
|
||||
|
|
|
|||
19
src/index.ts
19
src/index.ts
|
|
@ -1,6 +1,25 @@
|
|||
import express, { urlencoded, json } from 'express';
|
||||
import cors from 'cors';
|
||||
import api from '@/api';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
config();
|
||||
|
||||
const checkEnvVars = () => {
|
||||
const requiredEnvVars = ['PORT', 'DB_URL', 'JWT_SECRET', 'JWT_EXPIRES_IN'];
|
||||
let error: Boolean = false;
|
||||
requiredEnvVars.forEach((envVar) => {
|
||||
if (process.env[envVar] === undefined) {
|
||||
error = true;
|
||||
console.log(`${envVar} is undefined`);
|
||||
}
|
||||
});
|
||||
if (error) {
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
checkEnvVars();
|
||||
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue