-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (35 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();
const port = 3000;
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended:true }));
let todos = [];
app.get("/", (req, res) => {
res.render("index.ejs", { todos: todos });
});
function calcTime() {
const now = new Date();
const currentHour = now.getHours();
const currentMinute = now.getMinutes();
let formattedHour = currentHour < 10 ? `0${currentHour}` : currentHour;
const formattedMinute = currentMinute < 10 ? `0${currentMinute}` : currentMinute;
let currentTime;
if (formattedHour > 12) {
formattedHour %= 12
currentTime = `${formattedHour}:${formattedMinute}pm`
return currentTime
} else {
currentTime = `${formattedHour}:${formattedMinute}am`
return currentTime
};
};
app.post("/", (req, res) => {
let todoText = req.body.todo;
let currentTime = calcTime();
todos.push({ text: todoText, time: currentTime });
res.redirect("/")
});
app.listen('3000',function(){
console.log("server is running on port 3000...")
})