Skip to content

help me explain esmodules in nodejs #4946

Answered by VoltrexKeyva
WingDust asked this question in Q&A
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: 0 comments 4 replies

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
Category
Q&A
4 participants