Currently, the Server.js is going the too long. In the real world application, it's likely that we were going to deal with more routers, whichi means it growing even long Er.
A single file which have too many lines of code whcih means code small.
We are going to extract routes to modules.
Firstmean/routes/people.js:
/**/var express = require (' Express '); var people = require ('.. /controller/people ');
// return router instance which can be mounted as a middleware var router = Express. Router (); Router.route ('/') . Get (People.getall); Router.route ('/:id ') . Get ( People.get); // exports the router as a Node modulemodule.exports = router;
Server.js:
' Use strict '; var express = require (' Express '); var cors = require ("cors"); var app = Express (); App.use (Cors ()); var people = require ('./routes/people '); // Use router as a middlewareapp.use ('/people ', people); App.listen (3000);
[MEAN Stack] First API--7. Using Route Files to Structure Server Side API