diff --git a/.env.example b/.env.example index b271385..c4bdcc1 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ -DATABASE_URL='' -SECRET_KEY='' \ No newline at end of file +DB_URL='' +JWT_SECRET='' +JWT_EXPIRES_IN='1d' +PORT=5000 diff --git a/src/index.ts b/src/index.ts index 80b442b..6f0f211 100644 --- a/src/index.ts +++ b/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;