5 ms·
This project looks really nice, though I really wish there was an easy way to segment routes into multiple files since it seems like an application w/ any kind
by Judson 15y ago
This project looks really nice, though I really wish there was an easy way to segment routes into multiple files since it seems like an application w/ any kind of complexity would get out of hand quickly.
I didn't see a way by just skimming the docs - is there an easy way?
- weixiyen 15y agojust write a library that traverses a directory and include the files...
- furtivefelon 15y agothis works for me: include it in routes/index.js, and everything in your routes dir will be exposed if you do var routes = require('./routes') var files = fs.readdirSync('./routes') files.forEach(function(file){ if(file != 'index.js'){ var exp = require('./'+file); _.extend(exports, exp); } });
- maccman 15y agoYes, the 'app' global will be available in every file you require in.
- Skywing 15y agoHere's an example of my usual pattern, using express: https://github.com/ryancole/node-simple-upload/tree/master/node/src https://github.com/ryancole/node-simple-upload/tree/master/n... The routes are not namespaced like you'd see with something like Python's Flask does, but it still allows me to group all my similar routes.