help me explain esmodules in nodejs #43223
-
What is esmodules in nodejs ? I read doc and still don't understand |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You can take a look at this tutorial : https://blog.logrocket.com/commonjs-vs-es-modules-node-js/ |
Beta Was this translation helpful? Give feedback.
-
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:
There are more differences but these are the main differences that are focused upon. Overall it's recommended to use JavaScript's official way to modularize code (ESM) for increased stability and security, and the extended features it provides, if you're heading for backwards compatibility then you should still use CJS rather than ESM, if that's not your main focus, then ESM is the better choice. |
Beta Was this translation helpful? Give feedback.
-
Let's see this one. |
Beta Was this translation helpful? Give feedback.
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:
require()
function and dynamic …