Skip to content

help me explain esmodules in nodejs #43223

Answered by VoltrexKeyva
WingDust asked this question in General
Discussion options

You must be logged in to vote

CommonJS (CJS) was implemented as a way to modularize JavaScript code when JavaScript didn't officially have a way to do so, but now JavaScript has an official way to modularize code through ES (ECMAScript) modules (also known as ESM).

CJS isn't the only way to modularize code when JavaScript didn't have an official way to do so, there is also SystemJS, RequireJS, AMD (explained in RequireJS), etc etc. Although Node.js mainly uses CommonJS instead of the other ones.

The main differences are as follows:

  1. CJS module evaluation is not asynchronous, and does not support features such as Top-Level Await (TLA).
  2. Modules can be imported in CJS using both the global require() function and dynamic …

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@WingDust
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by avivkeller
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. esm Issues and PRs related to the ECMAScript Modules implementation.
4 participants