-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (50 loc) · 1.51 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require("express");
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/todolistDB",{useNewUrlParser: true});
const app= express();
var addtasks=[];
var addtask="";
var worktasks=[];
const itemSchema = {
name : String
};
const Item = mongoose.model("item", itemSchema)
const bodyparser= require("body-parser");
app.use(bodyparser.urlencoded({extended:true}));
//let ejs = require('ejs');
// const ejs= require("ejs");
app.set('view engine', 'ejs');
app.use(express.static("public"));
app.get("/",function(request,response){
// var today= new Date();
// var currentDay= today.getDay;
var today = new Date();
// var currentDay = today.getDay();
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var day=today.toLocaleDateString("en-US", options);
response.render("List",{
ListTitle:day,item:addtasks}
);
});
app.post("/",function(req,res){
console.log(req.body);
addtask= req.body.additionaltask;
if(req.body.add_button=="Work"){
worktasks.push(addtask);
res.redirect("/work");
}else{
addtasks.push(addtask);
res.redirect("/");
}
});
app.get("/work",function(request,response){
response.render("List",{
ListTitle:"Work List",item:worktasks
})
});
// app.post("/work",function(req,res){
// // addtask=req.body.additionaltask;
// })
app.listen(3000,function(){
console.log("Server is ported from 3000");
})