const express = require(‘express’)
const app= express()
app.use(express.json())
app.use(express.urlencoded({extended:true}))
app.use(’/’,express.static(__dirname+’/public’))
let todolist = []
app.get(’/todos’,(req,res)=>{
res.send(todolist)
})
app.post(’/addtodo’,(req,res)=>{
todolist.push({
name:req.body.name,
priority: +(req.body.priority || 1)
})
// res.redirect(’/todos’) // or res.send(‘Success’)
res.send({
todoID:todolist.length,
success:“true”
})
})
app.listen(4847,()=>{
console.log(“server started at http://localhost:4847”)
})