3 ms·
You can already accomplish this in Express by creating middleware and abstract routes for CRUD stuff. app.all('/users', middleware, routes.user); If you're ju
by viscanti 15y ago
You can already accomplish this in Express by creating middleware and abstract routes for CRUD stuff.
app.all('/users', middleware, routes.user);
If you're just doing CRUD on a route, that can be abstracted fairly easily. It can also help better organize your code on a larger project (a la MVC-ish), rather than the Sinatra-like feel.
Too many "beginner" express examples show everything in one big file. With all the route logic, etc all in one place, without any CRUD abstraction. Generally these demos are so small that they don't need any abstraction. It takes 20 minutes to write the whole thing, and it's not meant to do much in production. In a production environment, where you have a bigger app, you'll want to abstract away as much of the boilerplate code as possible. Luckily it's fairly trivial to compose abstract higher order functions in javascript to do just that.
- rgbrgb 15y agoThanks for sharing this tip. Do you by chance know of any tutorials on writing middleware that does this sort of thing?