June 2018
Intermediate to advanced
348 pages
8h 19m
English
Creating a new Match is simple. We just need to import the Match model and call its built-in save method, as follows:
const express = require('express')const api = express.Router()const Match = require('../models/match')api .route('/admin/match/:id?') .post((req, res, next) => { const match = new Match(req.body) match.save() .then(data => res.json(data)) .catch(err => next(err) ) }) .put((req, res, next) => { // logic to update Match })module.exports = api
First, we import the Match model. Then, in the POST method, we create a new Match object and call the save function. If the operation is successful, we send the new Match via the res.json method. To test our creation logic, we need to configure the server.js to use our ...
Read now
Unlock full access