4 ms·
This looks interesting, and although I'm already committed to an ad-hoc framework on my current projects, I'll check it out for future ideas (or to import some
by pfooti 11y ago
This looks interesting, and although I'm already committed to an ad-hoc framework on my current projects, I'll check it out for future ideas (or to import some of your ideas into my current projects).
Having the framework be batteries-included is nice, but also nice would be decomposing it into modules. For a good example of this, check out the Hapi.js server ecosystem. Lots of different plugins, and if you want object validation outside of the hapi.js world, you can just use Joi alone. It lets me mix-and-match stuff. A concrete thing here is the ORM layer (which hapi.js doesn't have). If I could pull your ORM out from the server stuff, I'd be a lot more likely to take that part at least for a spin.
- keithwhor 11y agoI'm sure as Nodal matures the core components will become more (and not less) modular. I'll make sure of it. Helps with testing, extensibility, etc. I've refactored several pieces numerous times as complexity (due to tight-coupling) became too high. The Composer (ORM) used to be twice the size, three modules, and not nearly as capable as it is now.
- pfooti 11y agoSome other minor things: promises are rad, and I know I can just use Bluebird's promisifyAll to wrap your code. But still, it would be nice if I didn't have to muck around with that and async methods called without a callback returned a promise by default. middleware is rad, it lets me abstract out pre-processing that happens on (say) every POST route to validate parameters. It doesn't look really feasible to do that with this system. I'd basically just have to bake all that into the post() method, which isn't super-modular and is probably harder to write unit tests for. can't say that I'm wild about regex routes by default. I dig stuff like 'items/:itemId' with named parameters in a microsyntax. Makes life a lot easier.
- keithwhor 11y agoNodal supports Middleware for post-processing controller output (gzip, etc.) and I could do something similar for pre-processing but right now it's just encouraged that you write your own intermediate controller, get all controllers to inherit from it and do something like a super call. Will think about what pre-processing middleware would look like / be called.
- pfooti 11y agoYah, I had thought about inheritance and super, but without multiple inheritance, it'd be tricky. Basically a lot of my routes do stuff like parameter validation (I store specific criteria on the model class, but apply them in the route), creating a new object from validated post params, loading from the database, storing to the database, authorizing and authenticating, etc. Then my route definition declares the per route middleware and the specific controller only has to encapsulate route specific business logic. I could do that just by putting it all in a utils package and calling loadItem(), validate params() etc at the top of each handler, but that feels less elegant. It may be that I've just been using hapi.js for too long, the modularity and composition in that framewrok.is quite elegant, IMO.
- novaleaf 11y agoI came here to mention Hapi, so I'll piggyback on your post. For those looking for an "enterprise" alternative to Express, give Hapi a try! It's very mature, has tons of extension modules (as pfooti mentions), and basically can do mostly everything you need without your needing to write much glue code. Also, if you use typescript, it has a .d.ts file at Definitely Typed. (I wrote it)