Express like Router Object
See original GitHub issueHi, first of all, thank you very much for this project and for being so kind when replying to the issues here.
With express js, I use router objects outside the main server.js file; from this file I require all the router objects and apply them by using app.use('/prefix', routerObj)
.
My main concern is code organization but I don’t know if using router objects is the best way to do it with express.
Anyways, it seems restana does not implement a Router Object like express (does it?).
So, given all this, do you have any suggestions for code organization using restana?
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Routing - Express.js
Use the express.Router class to create modular, mountable route handlers. A Router instance is a complete middleware and routing system; for this reason,...
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
First we create routes for a wiki in a module named wiki.js. The code first imports the Express application object, uses it to...
Read more >Express.js express.Router() Function - GeeksforGeeks
The express.Router() function is used to create a new router object. This function is used when you want to create a new router...
Read more >Guide to the Express Router Object — Request and ...
The Expressrouter object is a collection of middlewares and routes. It a mini-app within the main app. It also behaves like middleware ...
Read more >Express Router: How to Use Routing in Node.js - AppDividend
Express Router is a built-in class that refers to how an application's endpoints (URIs) respond to client requests. In addition, the express ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @jkyberneees,
I’m closing this issue because everything is working!
Thank you for suggesting the middleware-if-unless module. It’s definitely useful for my use case.
Instead of using middleware-if-unless though, I have refactored my loadRoutes function so that every request handler function receives four arguments: app, path, middlewares (array) and context (an object into which I can inject a DB reference, for example).
routes/api/getAllUsers.js
server.js
I’m looking forward to playing with restana version 4.
Thank you very much for all you’ve been doing!
You rock!