-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (34 loc) · 1000 Bytes
/
server.js
File metadata and controls
40 lines (34 loc) · 1000 Bytes
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
import config from 'config';
import mongoose from 'mongoose';
import app from './src/app';
import C from './src/utils/log';
/**
* uncaughtException means no code was looking for that exception
*/
process.on('uncaughtException', (error) => {
C(`uncaughtException 💥💥 ${error.name}: ${error.message}`);
});
/**
* connect to the database
*/
mongoose
.connect(config.get('DATABASE_LOCAL'), {
useNewUrlParser: true,
autoIndex: true,
})
.then(() => C('DB connection successful!'))
.catch((error) => C('💥💥 DB connection error', error));
const port = config.get('PORT');
const server = app.listen(port, () => {
C(`App running on port ${port}...`);
});
/**
* unhandledrejection event is sent to the global scope of a script when a JavaScript Promise
* that has no rejection handler is rejected
*/
process.on('unhandledRejection', (error) => {
C(`unhandledRejection 💥💥 ${error.name}: ${error.message}`);
server.close(() => {
process.exit(1);
});
});