-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (38 loc) · 1.08 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
const express = require("express");
const dotenv = require("dotenv");
const bookings = require("./routes/bookingRoute");
const dentists = require("./routes/dentistRoute");
const users = require("./routes/userRoute");
const connectDB = require("./config/db");
const auth = require("./routes/auth");
const cookieParser = require("cookie-parser");
// Load env vars
dotenv.config({ path: "./config/config.env" });
// Connect Database
connectDB();
const app = express();
// Body parser
app.use(express.json());
//Cookie parser
app.use(cookieParser());
// Mount routers
app.use("/api/v1/bookings", bookings);
app.use("/api/v1/dentists", dentists);
app.use("/api/v1/auth", auth);
app.use("/api/v1/user", users);
const PORT = process.env.PORT || 5200;
const server = app.listen(
PORT,
console.log(
"Server is running in",
process.env.NODE_ENV,
"mode on port",
PORT
)
);
// Handle unhandled promise rejections
process.on("unhandledRejection", (err, promise) => {
console.log(`Error : ${err.message}`);
// close server & exit process
server.close(() => process.exit(1));
});