forked from hiren-ghodasara/express-mongoose-es8-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (16 loc) · 840 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import debug from 'debug'
require('dotenv').load()
const log = debug('app')
let applicationEnvVars = [ 'APP_ENVIROMENT', 'PORT', 'USE_MONGODB', 'USE_MYSQL' ]
let mysqlEnvVars = [ 'MYSQL_HOSTNAME', 'MYSQL_PORT', 'MYSQL_USERNAME', 'MYSQL_DATABASE', 'MYSQL_PASSWORD' ]
let mongoEnvVars = [ 'MONGO_HOSTNAME', 'MONGO_PORT', 'MONGO_DATABASE' ]
if (process.env.USE_MONGODB === 'true') applicationEnvVars = [ ...applicationEnvVars, ...mongoEnvVars ]
if (process.env.USE_MYSQL === 'true') applicationEnvVars = [ ...applicationEnvVars, ...mysqlEnvVars ]
let unusedEnvVars = applicationEnvVars.filter((i) => !process.env[i])
if (unusedEnvVars.length) {
log('Required ENV variables are not set: [' + unusedEnvVars.join(', ') + ']')
process.exit(1)
}
const { app } = require('./server/app.js')
app.listen(process.env.PORT)
export default app