The Node.js Philosophy

Note: This post originally appeared on my previous blog, JavaScript Report.

I recently picked up a copy of Node.js Design Patterns by Mario Casciaro and Luciano Mammino. It’s really good and there is one part I’d like to share with you here - their explanation of the Node.js philosophy.

As they note, every platform has it’s own philosophy and paradigms. One of the keys to learning a new technology is to start with understanding the high-level principles and approaches behind its design - it’s philosophy.

Here are the key principles of Node.js according to Casciaro and Mammino:

  • Small core
  • Small modules
  • Small surface area
  • Simplicity and pragamatism

Small Core

Node itself has a limited set of functionality. It leaves the rest to the large and dynamic ecosystem of modules found on npm.

This principle has an enormous impact on the Node.js culture, as it gives freedom to the community to experiment and iterate quickly on a broader set of solutions within the scope of userland modules, instead of being imposed with one slowly evolving solution that is built into the more tightly controlled and stable core.

Small Modules

The idea here is that a single module will do one thing well. It is focused in scope.

The Node.js way, in fact, involves extreme levels of reusability, whereby applications are composed of a high number of small, well-focused dependencies. While this can be considered unpractical or totally unfeasible in other platforms, in Node.js this practice is encouraged. As a consequence, it is not rare to find npm packages containing less than 100 lines of code or exposing only one single function.

Small Surface Area

Here the small surface area refers to a limited API or set of functionality. It’s a principle that encourages usability and eases maintenance.

The main advantage here is that increased usability of the API, which means that the API becomes clearer to use and is less exposed to erroneous usage.

Simplicity and Pragmatism

Rather than try to model real-world complexity as in object-oriented design, the Node.js approach is to reduce complexity. This reflects back to the earlier principle of small modules. Small, focused modules that can be composed to create larger applications. Each individual piece is easy to understand and highly reusable.

Designing simple, as opposed to perfect, fully-featured software, is a good practice for several reasons: it takes less effort to implement, allows faster shipping with fewer resources, is easier to adapt, and is easier to manintain and understand.

Finally…

Technical books are expensive and, in my experience, often aren’t worth the money. This book, however, has been a good purchase. If you’re considering buying it for yourself, keep in mind that the authors assume the reader has previous experience writing software. So, it's not for novice software developers, but definitely worth the investment if you want to learn more about Node.js design patterns.

If you'd like to connect, I'm on Twitter and my DMs are open.