-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (45 loc) · 1.13 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const mongoose = require('mongoose');
const dotenv = require('dotenv');
process.on('unhandledRejection', (err) => {
console.log(err.name, err.message);
console.log(
'Unhandled Rejection !! Server shutting down...'
);
process.exit(1); //1 for unhandled rejection
});
process.on('uncaughtException', (err) => {
console.log(err.name, err.message);
console.log(
'Uncaught Exception!! Server shutting down...'
);
process.exit(1); //1 for unhandled rejection
});
dotenv.config({ path: './.env' });
// First read env variable then call app
const app = require('./app');
// DB url with password
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
// connect to our DB
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log(
'DB Connection successfully established'
);
});
console.log(process.env.NODE_ENV);
// Schema for our collections
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(
`Server is listening to ${port}...`
);
});