-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (26 loc) · 950 Bytes
/
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
const express = require("express")
const app = express()
const dotenv = require("dotenv")
const mongoose = require("mongoose")
const helmet = require("helmet")
const morgan = require("morgan")
const tasks = require("./routes/tasks")
const notFound = require("./middleware/not-found")
const errorHandlerMiddleware = require("./middleware/error-handler")
const port = process.env.PORT || 8080
dotenv.config()
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true }).then(console.log("Connected to MongoDB...."))
.catch((err) => console.log("Error in connection to MongoDB : " + err))
//To render static files :
app.use(express.static("./public"))
//middle ware
app.use(express.json())
app.use(helmet())
app.use(morgan("common"))
//routes
app.use("/api/v1/tasks", tasks)
app.use(notFound)
app.use(errorHandlerMiddleware)
app.listen(port, () => {
console.log(`App is connected to localhost:${port}`)
})