-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
84 lines (64 loc) · 1.83 KB
/
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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require("express");
const bodyparser = require("body-parser");
const app = express();
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/todolistDB",{
useUnifiedTopology: true,
useNewUrlParser: true
});
const List = new mongoose.Schema({
name :{
type: String,
required : true
}
});
const todo= new mongoose.model("todo",List)
app.use(bodyparser.urlencoded({extended:true}));
app.set('view engine','ejs');
//var newitems=[];
var workitems=[];
app.use(express.static("public"));
app.get("/",function(req,res){
var today = new Date();
var options = {weekday:"long",month:"long",day:"numeric"};
var datestring=today.toLocaleDateString("en-US",options);
todo.find(function(err , getlist){
if (err){
console.log(err)
}
else{
res.render('list.ejs',{newitems: getlist ,keyday: datestring});
}
})
//res.render('list.ejs',{newitems: ,keyday: datestring});
});
app.get("/:newpage",function(req,res){
console.log(req.params.newpage);
});
app.post("/work",function(req,res){
workitems.push(req.body.newwork);
res.redirect("/work");
});
app.post("/",function(req,res){
//newitems.push(req.body.newwork);
var newtodo = new todo({
name: req.body.newwork
})
newtodo.save();
res.redirect("/");
});
app.post("/delete",function(req,res){
var checkid = req.body.checkbox;
todo.deleteOne({ _id : checkid }, function (err) {
if (err){
console.log(err)
}
else{
console.log("Data Deletion Done");
}
});
res.redirect("/")
});
app.listen(3000,function(){
console.log("Server is running on port 30000");
});