-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (41 loc) · 1.25 KB
/
app.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
45
46
47
48
49
50
const express = require('express')
const app = express()
const moment = require('moment');
const mongoose = require('mongoose')
const morgan = require('morgan')
const bodyParser = require('body-parser')
require("dotenv").config()
const cors = require('cors')
const cookieParser = require('cookie-parser')
const createAdminIfNotExists = require('./controllers/createAdmin');
const errorHandler = require('./middleware/error')
//Import routes
const authRoutes = require('./routes/authRoutes');
const appointmentRoutes = require('./routes/appointmentRoutes');
//Database connection
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log('Database connection established');
createAdminIfNotExists();
})
.catch((err) => console.error(err));
//Middleware
app.use(morgan('dev'))
app.use(bodyParser.json({ limit: "5mb" }))
app.use(bodyParser.urlencoded({
limit: "5mb",
extended: true
}))
app.use(cookieParser())
app.use(cors())
//Routes Middleware
app.use('/api', authRoutes);
app.use('/api', appointmentRoutes);
//Error Middleware
app.use(errorHandler);
//port
const port = process.env.PORT || 9000
app.listen(port, () => { console.log(`Server start on port ${port}`) })