Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Last active February 14, 2024 01:41
Show Gist options
  • Save v-kolesnikov/05a7a53f8ff77c0f9a503b5b4a3fd6bd to your computer and use it in GitHub Desktop.
Save v-kolesnikov/05a7a53f8ff77c0f9a503b5b4a3fd6bd to your computer and use it in GitHub Desktop.
CommonJS
ESM
AMD
ES modules
ES6 modules
mjs
import, export
script defer
---
Node.js's original module system is CommonJs (which uses require and module.exports).
Since Node.js was created, the ECMAScript module system (which uses import and 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 "type": "module",).
https://nodejs.org/docs/latest/api/esm.html#esm_differences_between_es_modules_and_commonjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment