-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (22 loc) · 794 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
require('dotenv').config()
const express = require('express');
const app = express();
const path = require('path');
const errorHandler = require('./middleware/error');
const connectDB = require('./config/db')
connectDB();
const PORT = process.env.PORT || 5000;
app.use(express.json());
app.use(express.static(path.join(__dirname,'build')));
app.use(express.static(path.join(__dirname,'./public/')));
app.use('/api/auth',require('./routes/auth'))
app.use('/api/post',require('./routes/post'))
app.use(errorHandler);
const server = app.listen(PORT, () => console.log(`Server listening on ${PORT}.`));
process.on('unhandledRejection',(err,promise)=>{
console.log(err);
server.close(() => {
console.warn("closed MongoDb connection !!!");
process.exit(1);
});
});