CommonJS
CommonJS was a project with the goal to establish conventions on module ecosystem for JavaScript outside of the web browser. The primary reason for its creation was a major lack of commonly accepted form of JavaScript scripts module units which could be reusable in environments different from that provided by a conventional web browser e.g. web server or native desktop applications which run JavaScript scripts.
CommonJS's module specification is widely used today, in particular for server-side JavaScript with Node.js.[1] It is also used in the development of browser-side JavaScript, but the code must be packaged with a transpiler since browsers don't support CommonJS.[1] CommonJS can be recognized be recognized by the use of require()
and module.exports
. The other major server-side module specification is the ESM module specification (ES6 modules).[2] CommonJS can be recognized be recognized by the use of require()
and module.exports
while ESM uses import
and export
.
History
The project was started by Mozilla engineer Kevin Dangoor in January 2009 and initially named ServerJS.[3]
What I’m describing here is not a technical problem. It’s a matter of people getting together and making a decision to step forward and start building up something bigger and cooler together.
— Kevin Dangoor[3]
In August 2009, the project was renamed CommonJS to show the broader applicability of the APIs.[4] Specifications are created and approved in an open process. A specification is only considered final after it has been finished by multiple implementations.[5] CommonJS is not affiliated with the Ecma International group TC39 working on ECMAScript, but some members of TC39 participate in the project.[6]
Specifications
The list of specifications includes:[7]
Current
- Modules/1.0 (Superseded by Modules/1.1)
- Modules/1.1
- Modules/1.1.1
- Packages/1.0
- System/1.0
Proposals
The proposals cover much more than modules. They intend to define a set of APIs that are useful both for non-web JavaScript implementations, with standardized package names to provide interoperability within the ecosystem. This goal sometimes overlaps with that of TC39, and parts such as Promises have indeed made it into ECMAScript itself.
The part after the slash is the version. When a proposal is in contention, each individual proposal (including sequential revisions from the same author) is assigned a new letter. When the main direction is known it starts being assigned numeric versions.
- Binary/B,F
- Console (ported from Web)
- Encodings/A,C
- Encodings/A
- HTTP Client/B
- IO/A
- Filesystem/A,A/0
- Modules/Async/A
- Modules/AsynchronousDefinition
- Modules/LoaderPlugin
- Modules/Resources
- Modules/SimpleAsynchronous
- Modules/Transport/B,C,D,E
- Modules/Wrappings
- Modules/Wrappings-Explicit-Dependencies
- Packages/1.1
- Packages/AsynchronousDefinition
- Packages/Mappings/A,B,C,D
- Promises/B,D
- Unit Testing/B,1.0,1.0.1
Implementations
- Akshell[8]
- Common Node[9]
- CommonJS Compiler - a command-line tool that makes Common JS modules suitable for in-browser use[10]
- CommonJS for PHP - a light-weight CommonJS implementation for PHP 5.3+[11]
- CouchDB[12]
- Flusspferd[13]
- GPSEE[14]
- Jetpack
- Joyent Smart Platform[15]
- JSBuild[16]
- MongoDB[17]
- Narwhal (JavaScript platform)[18]
- Node.js (partial; synchronous)[19]
- Persevere[20]
- PINF JavaScript Loader[21]
- RingoJS[22]
- SilkJS[23]
- SproutCore[24]
- TeaJS[25]
- Wakanda[26]
- XULJet[27]
See also
- Comparison of server-side JavaScript solutions
- Document Object Model (DOM), a web browser client-side application programming interface (API) commonly available in JavaScript
- JSGI
References
- ^ 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.
- ^ 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.
- ^ a b What Server Side JavaScript needs - Blue Sky On Mars
- ^ CommonJS: JavaScript Standard Library
- ^ ProposalProcess - CommonJS Spec Wiki
- ^ CommonJS: the First Year - Blue Sky On Mars
- ^ "JavaScript Standard Library". CommonJS. Archived from the original on 2014-05-28. Retrieved 2014-05-28.
- ^ Server-side JavaScript development and hosting - Akshell
- ^ olegp/common-node @ GitHub
- ^ - GitHub
- ^ DrBenton/CommonJSForPHP - GitHub
- ^ Implementations/CouchDB - CommonJS Spec Wiki
- ^ Flusspferd - CommonJS platform | Javascript bindings for C
- ^ Implementations/GPSEE - CommonJS Spec Wiki
- ^ Implementations/Smart - CommonJS Spec Wiki
- ^ Homepage - JSBuild Archived 2011-01-04 at the Wayback Machine
- ^ MongoDB
- ^ Implementations/Narwhal - CommonJS Spec Wiki
- ^ Implementations/node.js - CommonJS Spec Wiki
- ^ Implementations/Persevere - CommonJS Spec Wiki
- ^ pinf/loader-js - GitHub
- ^ Implementations/RingoJS - CommonJS Spec Wiki
- ^ "SilkJS WWW Site". Archived from the original on 2017-09-12. Retrieved 2012-10-19.
- ^ Implementations/SproutCore - CommonJS Spec Wiki
- ^ Implementations/TeaJS - CommonJS Spec Wiki
- ^ Wakanda
- ^ xuljet - XUL JavaScript Enhanced Toolkit - Google Project Hosting