Created
June 7, 2018 04:12
-
-
Save saigowthamr/d31ae21cc820d4fd7d0554d09b3e2f3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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