-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (31 loc) · 983 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
33
34
35
36
37
38
39
40
41
42
43
44
45
import express from "express";
import bodyParser from "body-parser";
import { latestDate } from "./date.js";
import { workHeading } from "./date.js";
const app = express();
const PORT = process.env.PORT || 3030;
const items = ["Buy Car","Study node js"];
const workItems = ["Buy Groceries"];
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static('public'))
app.get("/", (req, res) => {
let currentDay = latestDate();
res.render("list.ejs", {listTitle: currentDay, taskList: items });
});
app.post("/", (req, res) =>{
let taskEntered = req.body["taskName"];
if(req.body.list === "Work"){
workItems.push(taskEntered);
res.redirect("/work");
}else{
items.push(taskEntered);
res.redirect("/")
}
});
app.get("/work", (req, res) => {
let titles = workHeading();
res.render("list.ejs", {listTitle: titles, taskList: workItems});
});
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});