Chapter 15: Code Sharing
This chapter analyzes what use cases are optimal for code sharing and how to solve common language compatibility problems. You also learn how you can write modular code with the best practices of Node that can be compiled to run in the browser without bloat by using
What can be shared?
The easiest way to answer whether a certain piece of code can be shared between the browser and server is to break down this question into two questions:
• Is it worthwhile to run the codebase in both environments?
• Do the APIs it depends on exist in both environments? If not, can they easily be replaced or added (also known as shimming)?
Answering the first question is normally easy, and the answer itself depends exclusively on your program and project. Answering the second question can be a little trickier.