简体   繁体   中英

Storing Routes in express.Router();

I am currently working on the backend for a little project in angular and express. Since there will be a lot of Routes, I decided to create a file for each route-block. After that, I am importing them into my server.js like this:

router = express.Router();
var routes = require('./routepath/route1');
routes(router);
routes = require('./routepath/route2');
routes(router);
routes = require('./routepath/route3');
routes(router);

Is there an easier way to do this? I don't want to call routes(router) for each routefile i create.

You can see https://github.com/praveen001/express-boilerplate/tree/master/src for a little cleaner example.

But you still have to import every route and add it manually, there is no escaping from it, as far as I know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM