-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
47 lines (40 loc) · 1.11 KB
/
index.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
// Require and call Express
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
// use css
app.use(express.static("public"));
// placeholder tasks
var task = [];
var complete = [];
// add a task
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});
// remove a task
app.post("/removetask", function(req, res) {
var completeTask = req.body.check;
if (typeof completeTask === "string") {
complete.push(completeTask);
task.splice(task.indexOf(completeTask), 1);
}
else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});
// get website files
app.get("/", function (req, res) {
res.render("index", { task: task, complete: complete });
});
// listen for connections
app.listen(8080, function() {
console.log('Testing app listening on port 8080')
});