Module Definition Patterns (II)

Learn about exporting an instance and modifying other modules.

Exporting an instance

We can leverage the caching mechanism of require() to easily define stateful instances created from a constructor or a factory, which can be shared across different modules. The following code shows an example of this pattern:

Get hands-on with 1200+ tech skills courses.