-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (30 loc) · 805 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
36
37
38
const express = require("express")
const cors = require("cors")
const path = require("path")
const app = express()
require("./Config/db")
const userRouter = require("./Routes/user.route")
app.use(cors())
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
// api/users : GET
// api/users/:id : GET
// api/users/ : POST
// api/users/:id : PATCH
// api/users/:id : DELETE
app.use("/api/users", userRouter)
app.use("/",(req,res)=>{
res.statusCode = 200;
res.send("<h1>Welcome to User Managemnt App</h1>")
})
// Route not found error
app.use((req,res,next)=>{
res.statusCode = 404;
res.send("<h1>404 Page not found!!!</h1>")
})
// Server error
app.use((error,req,res,next)=>{
res.statusCode = 500;
res.send("<h1>Server Error</h1>")
})
module.exports = app