What is the difference between .js and .mjs files?
- mjs an extension for EcmaScript modules
- An MJS file is a source code file containing an ES Module (ECMAScript Module) for use with a Node.js application.
ES Modules allow web and application developers to organize code into smaller reusable components.
NOTE: Some developers informally refer to MJS files as "Michael Jackson Script" files.
It indicates an ES6 module file.
Node.js's original module system is CommonJs (which uses
Since Node.js was created, the ECMAScript module system (which uses
export) has become standard and Node.js has added support for it.
Node.js will treat
.cjs files as CommonJS modules and
.mjs files as ECMAScript modules. It will treat
.js files as whatever the default module system for the project is (which is CommonJS unless package.json says
See also: Differences between ES6 module system and CommonJs