Skip to content

Instantly share code, notes, and snippets.

@saigowthamr
Created June 7, 2018 04:12
Show Gist options
  • Select an option

  • Save saigowthamr/d31ae21cc820d4fd7d0554d09b3e2f3d to your computer and use it in GitHub Desktop.

Select an option

Save saigowthamr/d31ae21cc820d4fd7d0554d09b3e2f3d to your computer and use it in GitHub Desktop.
app.get("/user", function(req, res) {
User.find({})
.then(data => {
res.status(200).send(data);
})
.catch(err => res.send("Something Went Wrong"));
});
app.post("/user", function(req, res) {
const name = req.body.name;
const age = req.body.age;
const user = User({
name,
age
});
user
.save()
.then(data => res.status(200).send(data))
.catch(err => res.send("Error occured"));
});
app.put("/user/:id", function(req, res) {
const name = req.body.name;
const age = req.body.age;
User.findByIdAndUpdate(
{ _id: req.params.id },
{
$set: {
name,age
}
},
{ new: true }
)
.then(data => res.send(data))
.catch(err => res.send(err));
});
app.delete("/user/:id", function(req, res) {
User.findByIdAndRemove({ _id: req.params.id })
.then(data => res.send(data))
.catch(err => res.send("Error Occured "));
});
module.exports.handler = serverless(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment