Javascript CommonJS vs ES Modules

1/1/1970

Javascript CommonJS vs ES Modules

enter image description here

Apart from that,

You can't selectively load only the pieces you need with require but with import, you can selectively load only the pieces you need, which can save memory.

Loading is synchronous(step by step) for require on the other hand import can be asynchronous(without waiting for previous import) so it can perform a little better than require.


.cjs (CommonJS):

.mjs (ES Modules):

Study Middleware by piyush garg. He said middleware are like plugins