-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathapp.js
70 lines (57 loc) · 1.14 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
const express = require('express')
const bodyParser = require('body-parser')
const notes = [{
noteId: 1,
noteContent: "Hey guys, add your important notes here."
}
]
const app = express()
app.set('view engine', 'ejs')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
app.get("/", function (req, res) {
res.render("home", {
data: notes
})
})
app.post("/", (req, res) => {
const noteContent = req.body.noteContent
const noteId = notes.length + 1;
notes.push({
noteId: noteId,
noteContent: noteContent
})
res.render("home", {
data: notes
})
})
app.post('/update', (req, res) => {
var noteId = req.body.noteId;
var noteContent = req.body.noteContent;
notes.forEach(note => {
if (note.noteId == noteId) {
note.noteContent = noteContent;
}
})
res.render("home", {
data: notes
})
})
app.post('/delete', (req, res) => {
var noteId = req.body.noteId;
var j = 0;
notes.forEach(note => {
j = j + 1;
if (note.noteId == noteId) {
notes.splice((j - 1), 1)
}
})
res.render("home", {
data: notes
})
})
app.listen(3000, (req, res) => {
console.log("App is running on port 3000")
})