-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (32 loc) · 1.16 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
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"));
var items = [];
app.get("/", function (req, res) {
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var d = new Date();
var dayName = days[d.getDay()];
var date = d.getDate();
var monthName = months[d.getMonth()];
var year = d.getFullYear();
var formattedDate = `${dayName}, ${date} ${monthName} ${year}`;
res.render("list", { currDay: formattedDate, newListItem: items });
});
app.post("/", function (req, res) {
var item = req.body.newItem;
console.log(item);
if (item == '') {
res.send('<script>alert("Please write something"); window.location="/";</script>');
}
else {
items.push(item);
res.redirect("/");
}
});
app.listen(3000, function () {
console.log("server started on port 3000");
})