-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 965 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
//package imports
require("dotenv").config({ path: "./config.env" })
const express = require("express");
const cors = require("cors");
//file imports
const logger = require("./utils/logger");
const connectDB = require("./config/database");
const errorHandler = require("./middleware/error");
//initialization
connectDB()
const app = express();
//imported middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors())
//custom middleware
app.use("/api/user", require("./routes/user"));
//error middleware
app.use(errorHandler)
//ports
const PORT = process.env.PORT || 4545
app.listen(PORT, () => logger.info(`Connected to port ${PORT}`))
// process termination after unhandles promise rejection
process.on("unhandledRejection", (error, promise) => {
if(error){
logger.error("Unhandled Promise Rejection Error :", error)
process.exit(1)
} else {
logger.info("Unhandled Promise Rejection Promise :", promise)
}
})