Enabling
History
Node.js has two module systems: CommonJS modules and ECMAScript modules.
Authors can tell Node.js to interpret JavaScript as an ES module via the .mjs
file extension, the package.json "type" field with a value "module",
or the --input-type flag with a value of "module". These are explicit
markers of code being intended to run as an ES module.
Inversely, authors can explicitly tell Node.js to interpret JavaScript as
CommonJS via the .cjs file extension, the package.json "type" field
with a value "commonjs", or the --input-type flag with a value of
"commonjs".
When code lacks explicit markers for either module system, Node.js will inspect the source code of a module to look for ES module syntax. If such syntax is found, Node.js will run the code as an ES module; otherwise it will run the module as CommonJS. See Determining module system for more details.