-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·33 lines (29 loc) · 891 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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const mongoose = require('mongoose');
const router = require('./router/index');
const errorMiddleware = require('./middlewares/error-middleware');
const PORT = process.env.PORT || 5000;
const app = express();
app.use(express.json());
app.use(cookieParser());
app.use(cors({
credentials: true,
origin: process.env.CLIENT_URL
}));
app.use('/api', router);
app.use(errorMiddleware); // error middleware should always come last!
const start = async () => {
try {
await mongoose.connect(process.env.DB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
})
app.listen(PORT, () => console.log(`Server started on PORT = ${PORT}`));
} catch (e) {
console.log(e);
}
}
start();