ECMAScript modules are [the official standard format][] to package JavaScript code for reuse. Modules are defined using a variety of [import][] and [export][] statements.

    The following example of an ES module exports a function:

    1. // addTwo.mjs
    2. function addTwo(num) {
    3. return num + 2;
    4. }
    5. export { addTwo };

    The following example of an ES module imports the function from addTwo.mjs:

    1. // app.mjs
    2. import { addTwo } from './addTwo.mjs';
    3. // Prints: 6
    4. console.log(addTwo(4));

    Node.js fully supports ECMAScript modules as they are currently specified and provides limited interoperability between them and the existing module format, [CommonJS][].

    Node.js contains support for ES Modules based upon the [Node.js EP for ES Modules][] and the [ECMAScript-modules implementation][].

    Expect major changes in the implementation including interoperability support, specifier resolution, and default behavior.