June 2018
Intermediate to advanced
348 pages
8h 19m
English
We previously created the teams-api.js file in the routes folder. Open that file and apply the following changes:
const express = require('express')const api = new express.Router()let teams = [ { id: 1, name: "Peru"}, { id: 2, name: "Russia"}]
First, we import the express module. From this module, we are declaring the api variable, which is an instance of express.Router. A teams variable has been created in order to host some fake data for the teams. We will use this router to configure our CRUD/HTTP handlers, as follows:
api .route('/teams') .get((req, res) => { res.json(teams) }) .post((req, res) => { })app.listen(3000, () => {...
Using the api route variable, we define the '/teams' path as root for the HTTP handlers. ...
Read now
Unlock full access