-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (31 loc) · 915 Bytes
/
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
const express=require('express')
const app=express()
const bodyParser=require('body-parser')
const PORT=5000
app.set('view engine','ejs')
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
var todolist=[]
app.get('/',(req,res)=>{
res.render('todo',{todolist:todolist})
})
app.post('/',(req,res)=>{
const todo=req.body.title;
console.log(todo,'todo')
if(todo!= ''){
console.log(todo!==null,'ml')
todolist.push(todo)
res.redirect('/')
}else{
res.send('Please fill the title');
}
})
app.get('/delete',(req,res)=>{
const element=req.query.element
// console.log(element)
// console.log(todolist,'todolist')
// console.log(todolist.indexOf(element),1)
todolist.splice(todolist.indexOf(element), 1);
res.redirect('/')
})
app.listen(PORT,()=>{console.log(`server started at ${PORT}`)})