forked from Code-Mergers/UI-Auth-Template-Using-MERN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (22 loc) · 765 Bytes
/
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
require('dotenv').config({ path: "./config.env" });
const express = require("express");
const cors = require('cors');
const connectDB = require("./database/db")
const errorHandler = require("./middleware/error")
connectDB();
const app = express();
app.use(cors());
app.use(express.json());
//Routes
app.use('/api/auth',require('./routers/auth'));
app.use('/api/private',require('./routers/private'));
//error handler - (keep it at last after all routes & middlewares)
app.use(errorHandler);
const PORT = process.env.PORT || 3000;
const server = app.listen(PORT, ()=>{
console.log(`Server running on port ${PORT}`);
});
process.on("unhandledRejection",(err,promise) =>{
console.log(`Logged error : ${err}`),
server.close(()=> process.exit(1));
})