-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 883 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
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;
mongoose
.connect(DATABASE, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log("Database connected!");
})
.catch((err) => {
console.log("Database Connection failed!\n", err);
mongoose.connection.close();
});
const server = app.listen(PORT || 8000, () => {
console.log(`Server is up at http://${DOMAIN}:${PORT}`);
});
//error handler
process.on("unhandledRejection", (err) => {
console.log(err.name, err.message);
console.log("UNHANDLED_REJECTION! Shutting down...");
server.close(() => {
process.exit(1);
});
});