-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (43 loc) · 1.19 KB
/
server.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
var express = require('express');
var app = express();
app.use('/',express.static('../todos'));
const port = process.env.PORT ? process.env.PORT : 8000;
app.listen(port,function(){
console.log(`App on ${port}`);
});
// Start MongoDB
var { Todo } = require("./mongodb");
// Router
app.use(function (req, res, next) {
next();
});
require('./routes/router')(app);
const router = express.Router();
/*
app.get('/getTodos',function(req,res){
let query = { text: { $exists: true } };
Todo.find(query, function(err,Todo){
if(err) return console.log(err);
if(Todo.length == 0){
res.send("");
} else {
res.send(Todo);
}
})
});
app.post('/',jsonParser,function(req,res){
console.log('got post method');
var listing = new Todo({text: req.body.todo.text, done:req.body.done})
console.log(req.body.todo);
console.log({text: req.body.todo, done:req.body.done});
listing.save(function(err,listing){
if(err) {
res.send(err);
} else {
Todo.find(function(err,Todo){
if(err) return console.log(err);
res.send(Todo)
});
}
});
});*/