Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose post new document

//Router file. After doing all your imports at beginning of file
const router = express.Router();
app.use('/pathforpostrequests', router);

router.post('/', controller.create, (req, res, next) => {
  res.status(200).json(res.locals.person);
});

// Controller file. After doing all your imports at beginning of file. Person is an example mongo schema you will need to setup in a schema file.
const controller = {
  create (req, res, next) {
    const {firstName, lastName, age} = req.body;
    const newPerson = new Person ({firstName, lastName, age});
    res.locals.person = newPerson;
    newPerson.save();
    next();
  },
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: facade js 
Javascript :: Add Navbar to React Redux CRUD App 
Javascript :: Fabricjs configurations 
Javascript :: undo pwa 
Javascript :: Serve JSON on a Specific Route 
Javascript :: like and dislike function 
Javascript :: cookie clicker get all badges hack 
Javascript :: constantly send a request until a desired response is recieved expressjs 
Javascript :: jquery excel export 
Javascript :: go-gitea/gitea 
Javascript :: matrix addition in javascript 
Javascript :: comparing oblects 
Javascript :: connect to local mongodb node 
Javascript :: Schalte das jQuery Migrate Script ab 
Javascript :: javascript checkbox in table cell not working 
Javascript :: create array, fill with spaces, convert to string and concat 
Javascript :: self or this javascript 
Javascript :: javascript unicode literal 
Javascript :: javascript query corrector 
Javascript :: get current user moralis web3 login 
Javascript :: make price comma jquery 
Javascript :: Scroll event throttling JS MDN 
Javascript :: javascript const scope = await angular.element(document.body).scope(); 
Javascript :: drag and drop pic using hooks pure js 
Javascript :: code of copy button in js 
Javascript :: typeorm sqlite Using Repositories 
Javascript :: npm resize div 
Javascript :: node javascript retry promise.all 
Javascript :: Private Class Methods and Accessors in es12 
Javascript :: hover over class apply to subclass 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =