-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
52 lines (44 loc) · 1.35 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
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const chalk = require('chalk');
const Doctor = require('./models/doctorModel');
const scheduleCronJob = require('./utils/cron');
dotenv.config({ path: './config.env' });
process.on('uncaughtException', (err) => {
console.log(chalk.red('Uncaught Exception!'));
console.log(chalk.red(err.name, err.message));
process.exit(1);
});
const app = require('./app');
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
const port = process.env.PORT || 8000;
let server;
mongoose.set('strictQuery', false);
mongoose
.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log(chalk.green('DB connection successful!'));
server = app.listen(port, () => {
console.log(chalk.green(`App running on port ${port}...`));
// eslint-disable-next-line global-require
const io = require('./socket').init(server);
io.on('connection', (socket) => {
console.log(`A client connected : ${socket.id}`);
});
});
})
.catch((err) => console.log(chalk.red(err)));
scheduleCronJob(Doctor);
process.on('unhandledRejection', (err) => {
console.log(chalk.red('Unhandled Rejection!'));
console.log(chalk.red(err.name, err.message));
server.close(() => {
process.exit(1);
});
});