-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (40 loc) · 1.1 KB
/
server.js
File metadata and controls
48 lines (40 loc) · 1.1 KB
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
import dotenv from 'dotenv';
import mongoose from 'mongoose';
process.on('uncaughtException', (err) => {
console.error('UNCAUGHT EXCEPTION! 💥 Shutting down...');
console.error(err.name, err.message);
process.exit(1);
});
import app from './App.js';
dotenv.config();
const port = process.env.PORT || 3000;
const host = process.env.HOST || '127.0.0.1';
const db = process.env.DATABASE_REMOTE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD,
);
mongoose
.connect(db)
.then(() => {
console.log('DB connection successful!');
})
.catch((err) => {
console.error('DB connection error💥: ', err);
});
const server = app.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});
process.on('unhandledRejection', (err) => {
console.error('UNHANDLED REJECTION! 💥 Shutting down...');
console.error(err);
server.close(() => {
process.exit(1);
});
});
// Heroku specific
process.on('SIGTERM', () => {
console.log('👋 SIGTERM RECEIVED. Shutting down gracefully');
server.close(() => {
console.log('💥 Process terminated!');
});
});