For server.js, we update the code by using the route instance. By using this, we can remove some duplicate code.
For example:
function (Request, Response) {}), App.post (function(request, Response) {}); App.get (function (Request, Response) {}), app. Delete function (Request, response) {});
There is a lot of '/people/' ...
Using Route instance:
App.route ('/people ') . Get (function(req, res) {}) function(req, RES) {}), App.route ('/people/:name ') . Get (function(req, res) {}) . Delete (function(req, res) {});
in We case:
Before:
// server.js' use strict '; var express = require (' Express '); var cors = require ("cors"); var app = Express (); App.use (Cors ()); var people = require ('./controller/people '); App.get ('/people ', People.getall); App.get ( '/people/:id ', people.get); App.listen (3000);
After
' Use strict '; var express = require (' Express '); var cors = require ("cors"); var app = Express (); App.use (Cors ()); var people = require ('./controller/people '); App.route ('/people ') . Get (People.getall); App.route ('/people/:id ') . Get (People.get); App.listen (3000);
[MEAN] 6. Using Express Route Instance