Skip to content
New issue

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

Adding End points to the server: Error : localhost:3000/cat not found #5

Open
keshavrddy opened this issue Aug 9, 2017 · 0 comments

Comments

@keshavrddy
Copy link

//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..
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant