Some of the common modules are:
CommonJS, AMD, RequireJS, ES(ECMAScript)6 Modules. Refer to this medium article for an in-depth explanation of how these modules are different.
Table of Contents
Syntax and explanation
Syntax:To include a module, the require() function is used with the name of the module:
2) import()import() & export() statements are used to refer to an ES module. Other modules with file types such as .json cannot be imported with these statements. They are permitted to be used only in ES modules and the specifier of this statement can either be a URL-style relative path or a package name. Also, the import statement cannot be used in embedded scripts unless such script has a type="module". A dynamic import can be used for scripts whose type is not “module”
How is require() different from import()One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() cannot be called conditionally, it always runs at the beginning of the file.
To use the require() statement, a module must be saved with .js extension as opposed to .mjs when the import() statement is used.
ES modules can be loaded dynamically via the import() function unlike require().