As mentioned in Chapter 1, The Importance of Good Code, clean code should be structured in a modular way. In the next few sections, we'll introduce you to the concept of modular design, before explaining the different module formats. Then, for the rest of the chapter, we will begin composing our project by incorporating existing Node modules.
But first, let's remind ourselves why modular design is important. Without it, the following apply:
- Logic from one business domain can easily be interwoven with that of another
- When debugging, it's hard to identify where the bug is
- There'll likely be duplicate code
Instead, writing modular code means the following:
- Modules are logical separations of domains—for example, for a simple social network, you might have a module for user accounts, one for user profiles, one for posts, one for...