Skip to content

Instantly share code, notes, and snippets.

@TheArhaam
Last active November 19, 2020 18:25
Show Gist options
  • Save TheArhaam/3f71a1cd4f5ef0a06c1093adc6815566 to your computer and use it in GitHub Desktop.
Save TheArhaam/3f71a1cd4f5ef0a06c1093adc6815566 to your computer and use it in GitHub Desktop.
randomlist list.js
const router = require("express").Router();
let Item = require("../../models/item.model");
// POST - Add new item to list
router.post("/item", (request, response) => {
Item({ name: request.body.item }).save()
.then((item) => { response.status(200).json("Item Added Successfully!"); })
.catch((err) => { response.status(400).json("Unable to add item: " + err); })
})
// GET - Fetch entire list
router.get("/", (request, response) => {
Item.find()
.then((list) => { response.status(200).json(list); })
.catch((err) => { response.status(400).json("Unable to fetch list: " + err); })
})
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment