// server.js

// BASE SETUP

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var morgan = require('morgan');

app.use(morgan('dev'));




app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || 8080;

var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/nodeapp');

var Bear = require('./app/models/bear');

var router = express.Router();

router.use(function(req,res,next){
    
   console.log(req.body);
   next();
});

router.get('/',function(req,res){
    res.json({
        message: 'Welcome Prince'
    });
});


router.route('/bears')
    //create a bear 
            .post(function(req,res){
               
                var bear = new Bear();
                bear.name = req.body.name;
                bear.save(function(err){
                    if(err)
                        res.send(err);
                        
                        res.json({message: req.body});
                })
})
        .get(function(req,res){
            Bear.find(function(err,bears){
                if(err)
                    res.send(err);
                res.json(bears);
            });
});


app.use('/api',router);

app.listen(port);
console.log('Server listening now');


@@ -993,24 +993,30 @@
 essage: 
-req.body
+'Beer Created'
 %7D);%0A    
@@ -1159,32 +1159,32 @@
  res.send(err);%0A
-
                 
@@ -1221,16 +1221,950 @@
 );%0A%7D);%0A%0A
+router.route('/bears/:bear_id')%0A        .get(function(req,res)%7B%0A            Bear.findById(req.params.bear_id,function(err,bear)%7B%0A                if(err)%0A                    res.send(err);%0A                res.json(bear);%0A            %7D);%0A%7D)%0A        .put(function(req,res)%7B%0A            Bear.findById(req.params.bear_id,function(err,bear)%7B%0A                if(err)%0A                    res.send(err);%0A                %0A                bear.name = req.body.name;%0A                bear.save(function(err)%7B%0A                    if(err)%0A                        res.send(err);%0A                    res.json(%7Bmessage: 'Beer Updated'%7D);%0A                %7D);%0A            %7D)%0A%7D)%0A        .delete(function(req,res)%7B%0A            Bear.remove(%7B%0A                _id: req.params.bear_id%0A            %7D,function(err,bear)%7B%0A                if(err)%0A                    res.send(err);%0A                res.json(%7Bmessage: 'Successfully deleted'%7D);%0A            %7D);%0A%7D);%0A%0A
 %0Aapp.use

PUt and delete