-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (36 loc) · 1.1 KB
/
index.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
43
44
45
46
47
48
49
const express = require('express');
const mongoose = require('mongoose');
const desuungRouter = require("./routes/desuung");
const app = express();
app.use(express.json()); //to get the detail from client in json function.
app.use(express.urlencoded({extended: true}));
app.use("/desuung", desuungRouter);
app.get("/desuung", (req, res) => {
res.send('GET ALL');
console.log("req.body");
})
app.get("/desuung/:id", (req, res) => {
res.send('GET' + req.params.id);
});
app.post("/desuung", (req, res) => {
console.log(req.body);
res.send('POST');
});
app.put("/desuung/:id", (req, res) => {
res.send('PUT');
});
app.delete("/desuung/:id", (req, res) => {
res.send('DELETE');
});
const start = async () =>{
const mongoURI = "mongodb://localhost:27017";
try {
await mongoose.connect(mongoURI,{
useNewUrlParser: true
});
app.listen(3000, () => console.log('Server started'));
} catch (error) {
console.log("Error starting server", error)
}
};
start();