We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
//cats.js var _ = require('lodash');
module.exports = function (app) { _cats = []; // Create app.post('/cat', function (req, res) { _cats.push(req.body); res.json({info: 'cat created successfully'}); } ); /* Read*/ app.get('/cat/:id', function (req,res){ res.send( _.find( _cats, { name: req.params.id } ) ); });
// Update app.put('/cat/:id', function (req, res) { var index = _.findIndex( _cats, { name: req.params.id } ); _.merge(_cats[index], req.body); res.json({info: 'cat updated successfully'}); });
// Delete app.delete('/cat/:id', function (req, res) { _.remove(_cats, function(cat){ return cat.name === req.params.id; }); res.json({info: 'cat removed successfully'}); }); };
//index.js var express = require('express'); var app = express(); var cats = require('./cats.js')(app);
var bodyparser = require('body-parser');
app.get('/', function (req,res) { res.send('Hello World'); //res.json({hello:'world'}); });
var server = app.listen(3000, function () { console.log('Server running at http://127.0.0.1:3000'); });
Ran nodemon index.js Also no records in the network tab..
The text was updated successfully, but these errors were encountered:
No branches or pull requests
//cats.js
var _ = require('lodash');
module.exports = function (app) {
_cats = [];
// Create
app.post('/cat', function (req, res) {
_cats.push(req.body);
res.json({info: 'cat created successfully'});
}
);
/* Read*/
app.get('/cat/:id', function (req,res){
res.send(
_.find(
_cats,
{
name: req.params.id
}
)
);
});
// Update
app.put('/cat/:id', function (req, res) {
var index = _.findIndex(
_cats,
{
name: req.params.id
}
);
_.merge(_cats[index], req.body);
res.json({info: 'cat updated successfully'});
});
// Delete
app.delete('/cat/:id', function (req, res) {
_.remove(_cats, function(cat){
return cat.name === req.params.id;
});
res.json({info: 'cat removed successfully'});
});
};
//index.js
var express = require('express');
var app = express();
var cats = require('./cats.js')(app);
var bodyparser = require('body-parser');
app.get('/', function (req,res) {
res.send('Hello World');
//res.json({hello:'world'});
});
var server = app.listen(3000, function () {
console.log('Server running at http://127.0.0.1:3000');
});
Ran nodemon index.js
Also no records in the network tab..
The text was updated successfully, but these errors were encountered: