-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (26 loc) · 880 Bytes
/
server.js
File metadata and controls
36 lines (26 loc) · 880 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
const dotenv = require('dotenv');
const mongoose = require('mongoose');
process.on('uncaughtException', err => {
console.log(err.name, err.message);
console.log('🚨 Uncaught Rejection, Shutting Down Gracefully...');
process.exit(1);
});
dotenv.config({ path: './config.env' });
const app = require('./app');
const PORT = process.env.PORT || 3000;
const DB_URL = process.env.DATABASE_URL.replace('<PASSWORD>', process.env.DATABASE_PASSWORD);
mongoose.connect(DB_URL)
.then(() => {
console.log('DB connection successful');
});
// start server
const server = app.listen(PORT, () => {
console.log(`App running on port: ${PORT}`);
});
process.on('unhandledRejection', err => {
console.log(err.name, err.message);
console.log('🚨 Unhandled Rejection, Shutting Down Gracefully...');
server.close(() => {
process.exit(1);
});
});