-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.21 KB
/
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
43
44
45
46
'use strict';
/*eslint-disable */
const express = require('express');
const mongoose = require('mongoose');
const ReminderModel = require('./core/db/model/reminder');
const logger = require('./logger/logger');
const s = require('./worker/scheduler');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 8080;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
require('./routes/routes')(app);
const MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING || 'mongodb://localhost:27017/data';
// start scheduler
s.schedulerFactory.start();
const options = {
autoIndex: false,
reconnectTries: 30,
reconnectInterval: 500,
poolSize: 10,
bufferMaxEntries: 0,
useNewUrlParser: true
};
const connectWithRetry = () => {
logger.logInfo('mongoDB connection with retry...');
mongoose.connect(MONGO_CONNECTION_STRING, options).then(()=>{
logger.logInfo('connected to mongo...');
}).catch(err =>{
logger.logError('MongoDB connection unsuccessful, retry after 5 seconds.', err);
setTimeout(connectWithRetry, 5000)
})
};
app.listen(PORT, _ => {
logger.logInfo(`server listening on ${PORT}`);
});
connectWithRetry();