SHARE
TWEET

Untitled

a guest Jun 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require('mongoose');
  2. const Schema = mongoose.Schema;
  3.  
  4. //Create the Item Schema
  5. const ItemSchema = new Schema({
  6.   name: {
  7.     type: String,
  8.     required: true,
  9.   },
  10.   date: {
  11.     type: Date,
  12.     default: Date.now
  13.   }
  14. });
  15.  
  16. module.exports = Item = mongoose.model('item', ItemSchema);
  17.  
  18.  
  19. router.post('/', (req, res) => {
  20.   const newItem = new Item({
  21.     name: req.body.name
  22.   });
  23.   newItem.save()
  24. .    then(item => res.json(item));
  25. });
  26.  
  27.  
  28. module.exports = router;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top