-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (35 loc) · 906 Bytes
/
index.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
const mongoose = require("mongoose");
const path = require("path");
require("dotenv").config({
path: path.join(__dirname, "config.env"),
});
const app = require("./app");
//database
const { PORT, DOMAIN, DATABASE } = process.env;
const server = () =>
app.listen(PORT || 8000, () => {
console.log(`We Are Up! At http://${DOMAIN}:${PORT}`);
});
mongoose
.connect(DATABASE, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log('Database connected!');
server();
})
.catch((err) => {
console.log('Database Connection failed!\n', err);
mongoose.connection.close();
});
//error handler
process.on("unhandledRejection", (err) => {
console.log(err.name, err.message);
console.log("UNHANDLED_REJECTION! Shutting down...");
server.close(() => {
process.exit(1);
});
});