-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (39 loc) · 1.06 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require("express");
const cors = require("cors");
const {todos} = require("./db");
const mongoose = require("mongoose");
const server = express();
server.use(express.json());
server.use(cors());
server.get("/gettodos", async (req,res) =>{
const todosInDb = await todos.find({});
res.json(todosInDb);
});
server.post("/posttodos", async (req,res) =>{
const title = req.body.title;
const description = req.body.description;
const todosInDb = await todos.create({
title,
description,
completed: false
});
// console.log(todosInDb);
res.json("todo added successfully");
});
server.put("/updatetodos" , async (req , res) =>{
const { id , completed} = req.body;
const _id = mongoose.Types.ObjectId(this_id);
const updatedDB = await todos.findByIdAndUpdate(
_id,
{
completed
},
{
new : true
}
);
res.status(200);
})
server.listen(8080, () =>{
console.log('server is running');
});