-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
43 lines (26 loc) · 813 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
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
var port = process.env.PORT || 8080;
let items = ["Buy Food"];
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/public"));
app.get("/", (req, res) => {
var today = new Date();
let options = {
weekday: "long",
day: "numeric",
month: "long"
};
let day = today.toLocaleDateString("en-US", options);
res.render("list", {kindOfDay: day, newListItems: items});
app.post("/", (req, res) => {
let item = req.body.newItem;
items.push(item);
res.redirect("/");
})
});
app.listen(port, function() {
console.log("Server running on port" + port);
});