Building Isomorphic JavaScript
Isomorphic JavaScript is a term that is used to describe JavaScript code that can run both in the browser and in Node.js. In other words, it is a library that can be used in both environments. In order to do that, you will limit yourself to the features that are available in both environments.
For example, you can’t use the fs
module in the browser, and you can’t use the window
object in Node.js.
Sometimes, we install dependencies in our projects that are designed to be used in the browser and we try to use them in Node.js, and vice versa. This is a common mistake that we need to avoid.
Most of the projects will specify which environment they are designed for. Here is an example from Lodash (https://lodash.com/):
Figure 6.5 – Image from the Lodash documentation that explains in detail how to install the library in both environments (https://lodash.com/)
It is quite clear that lodash is designed...