-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·42 lines (33 loc) · 1.18 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
const express = require('express')
const connectDB = require('./db/connect')
const moment = require("moment");
require('dotenv').config()
const logger = require('./middleware/logger')
const authorize = require('./middleware/authenticationMiddleware')
const notFound = require('./middleware/not-found')
const errorHandlerMiddleware = require('./middleware/error-handler')
const app = express()
const port = process.env.APP_PORT || 3000
app.use([logger]); // To log every request
app.use(express.json());
app.use(express.urlencoded({extended: false})); // to parse urlencoded request payload
app.use(express.static('./public'))
app.use('/api/members',require('./routes/api/member'))
app.use('/api/tasks',require('./routes/api/task'))
app.use('/api/authenticate',require('./routes/api/authenticate'))
app.use(notFound)
app.use(errorHandlerMiddleware)
app.get('/', (req, res) => {
res.send('Hello World!')
})
const start = async ()=>{
try{
await connectDB(process.env.MONGO_URI);
app.listen(port, () => {
console.log(`Express app listening at http://localhost:${port}`)
})
}catch (error){
console.log("Error starting app",error);
}
}
start()