-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (47 loc) · 1.44 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
require('dotenv').config();
const express = require("express");
const bodyParser = require("body-parser");
const date = require(__dirname +"/date.js");
const mongoose = require('mongoose');
const app = express();
mongoose.connect("mongodb+srv://admin-arpita:[email protected]/newListDB", {useNewUrlParser: true, useUnifiedTopology: true});
app.set("view engine", "ejs");
mongoose.set('useFindAndModify', false);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
const itemsSchema = {
name: String
};
const Item = mongoose.model("Item", itemsSchema);
app.get("/", function(req, res) {
let day = date.getDate();
Item.find({}, function(err, foundItems){
res.render("list", {listTitle: day, newListItems: foundItems });
});
});
app.post("/delete", function(req, res){
const checkedItemId = req.body.checkbox;
Item.findByIdAndRemove(checkedItemId , function(err){
if(!err){
console.log("Successfully deleted checked items!");
res.redirect("/");
}
});
});
app.get("/work", function(req, res) {
res.render("list", { listTitle: "Work", newListItems: workItems });
});
app.get("/about", function(req,res){
res.render("about");
});
app.post("/", function(req, res) {
var itemName = req.body.userInput;
const item = new Item({
name: itemName
});
item.save();
res.redirect("/");
});
app.listen(process.env.PORT || 3000, function() {
console.log(`Server is running! `);
});