-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (32 loc) · 822 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
32
33
34
35
36
37
38
39
40
41
42
43
44
/*=====================REQUIRES======================*/
require('dotenv').config({path:"./config.env"})
const express = require('express')
const connectDB= require('./config/db')
const errorHandler= require('./middlewares/error')
/*=====================REQUIRES======================*/
/*
* Connect DB
* */
connectDB();
const app = express();
const PORT = process.env.PORT || 5000;
app.use(express.json());
/*
* Routes
* */
app.use('/api/auth',require('./routes/auth'));
app.use('/api/private',require('./routes/blog'));
/*
* Error Handler
* */
app.use(errorHandler);
/*
* Run Server
* */
const server= app.listen(PORT,()=>
console.log(`Server running on port ${PORT}`)
);
process.on('unhandledRejection',(err,promise)=>{
console.log(`Loggeg Error: ${err}`)
server.close(()=>process.exit(1));
})