-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
59 lines (42 loc) · 1.6 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var express = require('express');
var routes = require('./routes/index.js');
const mongoose = require('mongoose');
var passport = require('passport');
var bodyParser = require('body-parser');
var config = require('./config.js');
var cronJob = require('cron').CronJob;
var tutorHandler = require('./handlers/tutorHandler');
var userHandler = require('./handlers/userHandler');
var app = express();
require('dotenv').load();
require('./passport/strategies')(passport);
mongoose.connect(config.db.uri).then(() => {
console.log('db connected');
}).catch(console.log);
mongoose.Promise = global.Promise;
app.use('/controllers', express.static(process.cwd() + '/app/controllers'));
app.use(bodyParser.urlencoded({ limit:'50mb',extended: false }));
app.use(passport.initialize());
routes(app, passport);
var port = config.app.port;
app.listen(port, function () {
console.log('Node.js listening on port ' + port + '...');
//clear received_today of all tutors every midnight
// clear received_today of all tutors every 5 mins
if (process.env.NODE_ENV == 'test') {
var job2 = new cronJob('*/5 * * * *', () => {
tutorHandler.clearReceivedToday();
}, null, true, 'Asia/Calcutta');
var job3 = new cronJob('*/5 * * * *', () => {
userHandler.sendClassNotifications();
}, null, true, 'Asia/Calcutta');
}else{
var job = new cronJob('0 0 0 * * *', () => {
tutorHandler.clearReceivedToday();
}, null, true, 'Asia/Calcutta');
var job3 = new cronJob('0 0 */2 * * *', () => {
userHandler.sendClassNotifications();
}, null, true, 'Asia/Calcutta');
}
});