Friday 24 April 2020

ES Modules or CommonJS for handling Modules across the Codebase?

I am setting up a Node.js (12.16.2 LTS) Backend and was wondering as to the following:Should I go with ES Modules (import & export) or CommonJS (export & require) way of handling my modules?Will I see any or have any advantage of using one over the other?Is going via the experimental feature the optimal choice over the long used one?Does 12.16.2 LTS support it without the experimental flag? As far as I understand, it requires the separation in the form of .mjs or .js file extension, or, by passing the experimental flag.I am comfortable enough with the CommonJS way of handling modules, but would like to explore any possible advantages of using ES Modules over CommonJS.What I read so far :Dynamic loading of modules is supported in CommonJS. But ES Modules allows pre-parsing of the modules and thus can enable in tree-shaking (not eyeing for anyway).Syntax matches with the famous frontend frameworks (not a worthy point for me).

Submitted April 24, 2020 at 07:23PM by rchougule

No comments:

Post a Comment