commit
25ab2a4247
@ -0,0 +1 @@
|
||||
node_modules
|
||||
@ -0,0 +1,29 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var Comments = require('../models/comments.js');
|
||||
|
||||
router.get('/', function(req,res){
|
||||
Comments.find({}, function(err, foundComments){
|
||||
res.json(foundComments);
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/', function(req,res){
|
||||
Comments.create(req.body, function(err, createdComment){
|
||||
res.json(createdComment);
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/:id', function(req, res){
|
||||
Comments.findByIdAndRemove(req.params.id, function(err, removedComment){
|
||||
res.json(removedComment);
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/:id', function(req, res){
|
||||
Comments.findByIdAndUpdate(req.params.id, req.body, {new:true}, function(err, updatedComment){
|
||||
res.json(updatedComment);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -0,0 +1,9 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var commentSchema = mongoose.Schema({
|
||||
body:String
|
||||
});
|
||||
|
||||
var Comments = mongoose.model('Comment', commentSchema);
|
||||
|
||||
module.exports = Comments;
|
||||
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "stupidcomments",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
var port = process.env.port || 3000;
|
||||
var MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/stupidcomments'
|
||||
var mongoose = require('mongoose');
|
||||
var bodyParser = require('body-parser');
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
var commentsController = require('./controllers/comments.js');
|
||||
app.use('/comments', commentsController);
|
||||
|
||||
mongoose.connect(MONGODB_URI);
|
||||
|
||||
mongoose.connection.once('open', function(){
|
||||
console.log('connected to mongo');
|
||||
});
|
||||
|
||||
app.listen(port, function(){
|
||||
console.log('listening');
|
||||
});
|
||||
Loading…
Reference in new issue