Chapter 10. Modules
The goal of modular programming is to allow large programs to be assembled using modules of code from disparate authors and sources and for all of that code to run correctly even in the presence of code that the various module authors did not anticipate. As a practical matter, modularity is mostly about encapsulating or hiding private implementation details and keeping the global namespace tidy so that modules cannot accidentally modify the variables, functions, and classes defined by other modules.
programmers working on large code bases did their best to use the weak
modularity available through classes, objects, and
closures. Closure-based modularity, with support from code-bundling
tools, led to a practical form of modularity based on a
function, which was adopted by Node.
require()-based modules are a
fundamental part of the Node programming environment but were never
defines modules using
export keywords. Although
export have been part of the language for years, they
were only implemented by web browsers and Node relatively
depends on code-bundling tools.
The sections that follow cover:
Do-it-yourself modules with classes, objects, and closures
Node modules using
ES6 modules using