Chapter 7. Building modular applications with plugins

 

This chapter covers

  • Defining plugins and why you should use them
  • Creating and loading plugins
  • Building applications in a modular way using plugins
  • Communicating and sharing data between plugins

When building software we strive for modularity at many different layers. We package reusable statements into functions and functions into modules and classes. More recently we’ve started using tools like Browserify and React to split our front end into modules and components too.

Modularizing helps us to draw a line around something and says this does X, without anyone else (or our future selves) having to worry about how it does X. When working on a modular application, the cognitive load is reduced. We can lock away in the back of our minds all the messy details of the rest of the system and focus on the piece that we’re working on.

Despite developers having been aware of these benefits for a long time, the way we often see servers being built with Node.js is in a monolithic fashion. I’ve seen many Node applications with a single app.js or server.js file that contains the entire logic for the server. What happened to the modularity?

7.1. Plugged-in thinking

7.2. Creating and loading plugins

7.3. Composing plugins with Glue

7.4. Plugin communication

7.5. Summary