-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (37 loc) · 1.06 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
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
const items=["Buy Food","Cook Food","Eat Food"];
const workItems = [];
app.get("/", function (req, res) {
const today = new Date();
const options ={
weekday : "long",
day : "numeric",
month : "long"
};
const day = today.toLocaleDateString("en-US",options);
res.render("list", {listTitle: day , newListItems: items});
})
app.post("/" ,function(req,res){
const item = req.body.newItem;
if(req.body.list === "work"){
workItems.push(item);
res.redirect("/work");
}else{
items.push(item);
res.redirect("/");
}
})
app.get("/about",function(req,res){
res.render("about");
})
app.get("/work",function(req,res){
res.render("list",{listTitle: "Work List", newListItems: workItems })
})
app.listen(5000, function () {
console.log("Server running on port 5000");
})