-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 1.01 KB
/
server.js
File metadata and controls
39 lines (31 loc) · 1.01 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
const mongoose = require('mongoose');
const chalk = require('chalk');
const app = require('./index.js');
require('dotenv').config();
const port = process.env.PORT || 3000;
const log = console.log;
//App operations
log(chalk.cyan('✅ App Started'));
const DB = process.env.DATABASE_STRING.replace('<PASSWORD>', process.env.DATABASE_PASSWORD);
mongoose.connect(DB, {
useNewUrlParser: true, // After mongoose version 5.7.1 release
useUnifiedTopology: true
}).then(() => {
log(chalk.cyan(`✅ MongoDB connected successfully`));
})
app.listen(port, () => {
log(chalk.cyan(`✅ Server started at http://localhost:${port}`));
});
process.on('unhandledRejection', err => {
console.log(err.name, err.message);
console.log('Unhandled Error Detected! 💥 Closing down the application...');
server.close(() => {
process.exit(1);
});
});
process.on('SIGTERM', () => {
console.log('SIGTERM received. Shutting down the server 👋');
server.close(() => {
console.log('💥 Process terminated');
});
});