CommonJS

CommonJS is a project to standardize the module ecosystem for JavaScript outside of web browsers (e.g. on web servers or native desktop applications).

CommonJS's specification of how modules should work is widely used today for server-side JavaScript with Node.js.[1] It is also used for browser-side JavaScript, but that code must be packaged with a transpiler since browsers don't support CommonJS.[1] The other major module specification in use is the ECMAScript (ES) modules specification (ES6 modules aka ES2015 modules).[2] CommonJS can be recognized by the use of the require() function and module.exports, while ES modules use import and export statements for similar (though not identical) functionality.

  1. ^ a b Eric Elliott (26 June 2014). Programming JavaScript Applications: Robust Web Architecture with Node, HTML5, and Modern JS Libraries. "O'Reilly Media, Inc.". pp. 87–. ISBN 978-1-4919-5027-2.
  2. ^ Mario Casciaro; Luciano Mammino (29 July 2020). Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques, 3rd Edition. Packt Publishing. p. 62. ISBN 978-1-83921-044-0.