-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
42 lines (35 loc) · 994 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const config = require('config');
const mongodb = require('./database/mongo');
const { initServer } = require('./server');
const { log, createSuperAdmin, insertTestData } = require('./lib');
const CREATE_TEST_DATA = config.get('createTestData');
module.exports = (async () => {
// Initialize database connection
try {
await mongodb.start();
} catch (error) {
log.error('Error starting database!', error);
process.exit(1);
}
// Start server
try {
const server = await initServer();
await server.start();
} catch (error) {
log.error('Error starting server!', error);
process.exit(1);
}
try {
await createSuperAdmin();
} catch (error) {
log.error('Error creating superadmin! ', error);
}
if (CREATE_TEST_DATA) {
try {
await insertTestData();
} catch (error) {
log.error('Error inserting test data! Might happen because test data already exists. ');
}
}
log.info('Service started successfully!');
})();