In the previous section, we looked at how we can break up the business logic of our applications into smaller, more manageable chunks through plugins. We did this by attaching routes directly to the server
object passed into the register, which is probably the simplest use case with plugins. But plugins won't always be used for just routing; you could perform logic on server start as with blipp
, initialize database connections, create models for interacting with your data, and so on.
With developers still getting used to structuring server-side applications and the asynchronous nature of JavaScript, these types of use cases often are the beginning of messy or unstructured code due to the number of responsibilities placed on the developer. First of all, dependencies need to be acknowledged and dealt with in a sensible way—in the preceding examples, the database connection needs to be initialized before providing any model functionality. Secondly, we want a clean...