-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (30 loc) · 767 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");
require("./config/db");
const userRouter = require("./routes/user.route");
const app = express();
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/api/users", userRouter);
// api/users : GET
// api/users/:id : GET
// api/users/ : POST
// api/users/:id : PATCH
// api/users/:id : DELETE
app.get("/", (req, res) => {
res.sendFile(__dirname + "/./views/index.html");
});
// route not found error
app.use((req, res, next) => {
res.status(404).json({
message: "route not found",
});
});
// handling server error
app.use((err, req, res, next) => {
res.status(500).json({
message: "Something broke",
});
});
module.exports = app;