Learning web development: Modules and testing in JavaScript
Briefly

Modules are JavaScript files that encapsulate code and keep declarations local by default. The export keyword makes specific values accessible to other modules. The import statement specifies a source file using either a full URL or a relative path with Unix-style slashes; relative paths begin with ./ or ../. Named imports are listed in curly braces and create variables in the importing module whose values come from the exported items. Node.js can execute module files directly. A library is a collection of modules that provides reusable functionality, and many libraries are distributed via npm.
Let's start with the module simple-module/library.js: Roughly, module is just another name for JavaScript file. Normally, everything we create inside a module is only accessible within that module. That changes if we write export before (e.g.) a const variable declaration - as we did above. Now we can import the function add() from another module - e.g., the module simple-module/main.js:
from './library.js': What file are we importing from? It can be a full URL with a protocol or a relative path (the segment separators must be slashes - like in Unix). Relative paths start with either one or two dots. import { add }: What are we importing from library.js? If we import individual items, they are enclosed in curly braces and separated by commas. The import statement is similar to a variable declaration in that it also creates a variable in the current module.
Read at 2ality
[
|
]