-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (29 loc) · 935 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
33
34
35
const connectdb = require("./database/db")
// const Task = require("./models/task")
const express = require("express")
// const tas
const router = express.Router()
require("dotenv").config()
const app = express()
const task = require("./routes/task")
const notFound = require("./middleware/not-found")
const errorHandlerMiddleware = require("./middleware/errorhandler")
app.use(express.urlencoded({extended:false}))
app.use(express.json())
app.use("/api/task", task)
// app.all("*", (req,res)=>{
// console.log("page does'nt exist")
// res.status(404).json({msg: `page does'nt exist`})
// })
app.use(notFound)
app.use(errorHandlerMiddleware)
const port = 5000
const start = async()=>{
try {
await connectdb(process.env.Mongo_URI)
app.listen(port, ()=>{console.log("server listening on port " + port+"...")})
} catch (error) {
console.log("unnable to connnect to database")
}
}
start()