Created
July 8, 2015 07:16
-
-
Save SuThaw/1a6ea6a5a6ceab1fade4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var Todo = require('./models/todo'); | |
var app = express(); | |
//app.use(bodyParser.urlencoded({extended:false})); | |
app.use(bodyParser.json()); | |
app.get('/api/todos',function(req,res,next){ | |
Todo.find(function(err,todos){ | |
if(err) next(err); | |
return res.status(200).json(todos); | |
}); | |
}); | |
app.post('/api/todos',function(req,res,next){ | |
var todo = new Todo({ | |
user:req.body.user, | |
todo:req.body.todoBody | |
}); | |
todo.save(function(err,todo){ | |
if(err) next(err); | |
return res.status(201).json(todo); | |
}); | |
}); | |
app.put('/api/todos',function(req,res,next){ | |
Todo.findById(req.body.id,function(err,todo){ | |
if(err) next(err); | |
todo.finish = true; | |
todo.save(); | |
return res.status(200).json(todo); | |
}); | |
}); | |
app.listen(3000,function(){ | |
console.log('server is listening on', 3000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment