Making a node module which works both on frontend and backend
If theres some logic which needs to run on both frontend (JavaScript/HTML) and backend (NOdeJS) then there are some patterns which allow you to use the same module in both places.
It basically comes down to:
- Ensure the module has no dependencies on other node modules
- Ensure the module just exports a basic javascript object which can be iterated for serialisation
- Iterate through the module's exported object and JSON-ify and data and toString-ify any function definiton