Before ES6 Modules
For a long time, JavaScript existed without a built-in module construct. At first, this was not a problem because initially scripts were small and simple, so there was no need. But eventually, JavaScript programs became more and more complex. Hence, the community invented a variety of ways to organize code into modules. To name some (for historical reasons):
- AMD – one of the most ancient module systems, initially implemented by the library require.js.
- CommonJS – the module system used by NodeJS.
- UMD – meant to be a universal system, compatible with AMD and CommonJS.
JavaScript community is adopting ES6 modules, but the legacy systems are still in use. In particular, the CommonJS module system is still the primary way Node applications are written. We shall learn about it when we learn about NodeJS.