2017-11-30 03:52:44 +00:00
|
|
|
var express = require('express')
|
|
|
|
var bodyParser = require('body-parser')
|
|
|
|
|
|
|
|
var {mongoose} = require('./db/mongoose')
|
|
|
|
var {User} = require('./models/user')
|
|
|
|
var {Todo} = require('./models/todo')
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
|
|
|
|
app.post('/todos', (req, res) => {
|
|
|
|
var todo = new Todo({
|
|
|
|
text: req.body.text
|
|
|
|
});
|
|
|
|
|
|
|
|
todo.save().then((doc) => {
|
2017-11-30 04:15:25 +00:00
|
|
|
return res.send(doc);
|
2017-11-30 03:52:44 +00:00
|
|
|
}, (e) => {
|
2017-11-30 04:15:25 +00:00
|
|
|
return res.status(400).send(e);
|
|
|
|
});
|
|
|
|
});
|
2017-11-30 03:52:44 +00:00
|
|
|
|
2017-11-30 04:15:25 +00:00
|
|
|
app.listen(8888, () => {
|
|
|
|
console.log("Started on port 8888");
|
2017-11-30 03:52:44 +00:00
|
|
|
});
|
2017-11-30 04:15:25 +00:00
|
|
|
|
|
|
|
module.exports = {app}
|