-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 823 Bytes
/
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
const mongoose = require('mongoose');
const app = require('./src/app');
require('dotenv').config();
process.on('uncaughtException', err => {
console.warn('UNHANDLED EXCEPTION... Shutting down!');
console.error(err);
process.exit(1);
});
const dbURL =
process.env.NODE_ENV === 'development'
? process.env.dev_db
: process.env.prod_db;
mongoose
.connect(dbURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('mongodb connected'));
const port = process.env.PORT || 3000;
const server = app.listen(port, () =>
console.log('server listening on port ' + port)
);
process.on('unhandledRejection', err => {
console.warn('UNHANDLED REJECTION... Shutting Down!');
console.error(err);
server.close(() => process.exit(1));
});