Easy way to do controllers using express
With support to Async/Await and Generator based control flow
Create a new file to be a controller;
Import the library
const Controller = ;
const ctrl = '/' ;
A filter is an abstraction for any route middleware used by the express, so it is a function with this signature:
Check out Express.js docs for more info.
moduleexports = ctrlroutes;
const app = ;app;app;// ...app;// OR, if those are in a path:;
In the example,
walk is a library to get all files from a path, you can find here.
If you want to have
async methods inside one route logic, just do it:
If you want to yield your code, with promises, inside a generator, this is supported too
This is done using
simplerunner library info here.
Once more, the error treatment is express-ish, just append this after your routes:
More info here.
This errors include exceptions and rejections threw by the yield/awaited functions as well.