-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
113 lines (69 loc) · 1.74 KB
/
app.js
File metadata and controls
113 lines (69 loc) · 1.74 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("public"));
mongoose.connect('mongodb://127.0.0.1:27017/TodoDB');
const notesSchema = {
heading: String,
note: String
};
const Note = mongoose.model("note",notesSchema);
const note1 = new Note({
heading: "Hello World",
note: "Keep your notes posted here"
});
// note1.save();
var link;
app.get("/", function(req,res){
Note.find({}).then(function(doc){
// console.log(doc);
link = "/"
res.render("index.ejs",{
link:link,
notes:doc
});
});
});
app.post("/",function(req,res){
var head = req.body.title
var cont = req.body.para
if(head || cont){
const newNote = new Note({
heading: head,
note: cont
});
newNote.save();
res.redirect("/");
}
else{
res.redirect("/");
}
});
app.post("/delete",function(req,res){
let id = req.body.deleteId
Note.findByIdAndRemove(id).exec();
res.redirect("/");
});
// app.get("/work", function(req,res){
// link = "/work"
// res.render("index.ejs",{
// link:link,
// heading:workHeading,
// content:workContent
// });
// });
// app.post("/work",function(req,res){
// var head = req.body.title
// var cont = req.body.para
// if(head || cont){
// workHeading.push(head);
// workContent.push(cont);
// res.redirect("/work");
// }
// });
app.listen(port, () => {
console.log("Server is running..");
});