forked from juhiechandra/Institute-Website-Backend
-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
44 lines (35 loc) · 1 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
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const app = require("./app");
const {admin_panel,router} = require('./admin_panel')
//----------------------------------->
process.on("uncoughtException", (err) => {
console.log("uncought exception occured");
console.log(err.name, err.message);
process.exit(1);
});
dotenv.config({ path: "./.env" });
mongoose
.connect(process.env.URI, {
useNewUrlParser: true,
})
.then(() => {
console.log("connection to database eshtablished");
})
.catch((err) => {
console.log(err);
});
//server listening------------------------------------------------->
const port = process.env.PORT || 8000;
const server = app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
//admin panel
app.use(admin_panel.options.rootPath, router)
process.on("unhandledRejection", (err) => {
console.log("unhandleed rejection occured");
console.log(err.name, err.message);
server.close(() => {
process.exit(1);
});
});