-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (61 loc) · 1.44 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { urlencoded } = require('express');
const express=require('express');
const path=require('path');
const port=8000;
const app=express();
const db=require('./config/todo');
const Todo=require('./models/todo_schema');
app.set('view engine','ejs');
app.set('views',path.join(__dirname,'views'));
app.use(urlencoded());
app.use(express.static('assets'));
var todoarr=[
{
description:'mongo is love',
category:'work',
date:'12/2/2019'
}
]
app.get('/',function(req,res){
Todo.find({},function(err,data){
if(err)
{
console.log('error');
}
return res.render('index',{
title:'go way',
to:data
})
})
})
app.post('/create',function(req,res){
Todo.create({
description:req.body.description,
category:req.body.category,
date:req.body.date
},function(err,data){
if(err){
console.log('could not post data');
}
console.log("#####",data);
res.redirect('back');
})
})
app.get('/delete/',function(req,res){
let id=req.query.id;
console.log(id);
Todo.findByIdAndDelete(id,function(err){
if(err)
{
console.log('cant find');
}
return res.redirect('back');
})
})
app.listen(port,function(err){
if(err)
{
console.log("got an error on connext port",port)
}
console.log("server is running on a port:",port);
})