CommonJS

{{Short description|JavaScript outside of the web browser}}

{{Redirect|Common.JS|usage of JavaScript in Wikipedia|Wikipedia:Common.js and common.css|selfref=yes}}

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.{{cite book|author=Eric Elliott|url=https://books.google.com/books?id=jUfnAwAAQBAJ&pg=PA87|title=Programming JavaScript Applications: Robust Web Architecture with Node, HTML5, and Modern JS Libraries|date=26 June 2014|publisher="O'Reilly Media, Inc."|isbn=978-1-4919-5027-2|pages=87–}} It is also used for browser-side JavaScript, but that code must be packaged with a transpiler since browsers don't support CommonJS. The other major module specification in use is the ECMAScript (ES) modules specification (ES6 modules aka ES2015 modules).{{cite book|author1=Mario Casciaro|url=https://books.google.com/books?id=xBr0DwAAQBAJ&pg=PA62|title=Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques, 3rd Edition|author2=Luciano Mammino|date=29 July 2020|publisher=Packt Publishing|isbn=978-1-83921-044-0|pages=62}} 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.

History

The project was started by Mozilla engineer Kevin Dangoor in January, 2009 and initially named ServerJS.{{Cite web|title=What Server Side JavaScript needs ·|url=https://www.blueskyonmars.com/2009/01/29/what-server-side-javascript-needs/|access-date=2021-08-05|website=www.blueskyonmars.com}}

{{cquote|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.|15px || Kevin Dangoor}}

In August 2009, the project was renamed CommonJS to show the broader applicability of the APIs.{{Cite web|title=CommonJS: JavaScript Standard Library|url=http://www.commonjs.org/history/|access-date=2021-08-05|website=www.commonjs.org|archive-date=2017-11-13|archive-url=https://web.archive.org/web/20171113103236/http://www.commonjs.org/history|url-status=dead}} Specifications are created and approved in an open process. A specification is only considered final after it has been finished by multiple implementations.{{Cite web|title=ProposalProcess - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/ProposalProcess|access-date=2021-08-05|website=wiki.commonjs.org}} CommonJS is not affiliated with the Ecma International group TC39 working on ECMAScript, but some members of TC39 participate in the project.{{Cite web|title=CommonJS: the First Year ·|url=https://www.blueskyonmars.com/2010/01/29/commonjs-the-first-year/|access-date=2021-08-05|website=www.blueskyonmars.com}}

Specifications

The list of specifications includes:{{cite web|url=http://commonjs.org/specs/ |archive-url=https://web.archive.org/web/20140528134342/http://www.commonjs.org/specs/|archive-date=2014-05-28|title=JavaScript Standard Library |publisher=CommonJS |url-status=unfit |access-date=2014-05-28}}

= Current =

{{columns-list|colwidth=22em|

  • 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.

{{columns-list|colwidth=22em|

  • 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

{{columns-list|colwidth=22em|

  • Common Node{{Cite web|title=olegp/common-node @ GitHub|url=https://olegp.github.io/common-node/|access-date=2021-08-05|website=olegp.github.io}}
  • CommonJS Compiler - a command-line tool that makes Common JS modules suitable for in-browser use{{Cite web|title=CommonJS Compiler - makes your Common JS modules suitable for in-browser use|url=https://dsheiko.github.io/cjsc/|access-date=2021-08-05|website=dsheiko.github.io}}
  • CommonJS for PHP - a light-weight CommonJS implementation for PHP 5.3+{{Cite web|title=GitHub - DrBenton/CommonJSForPHP: A simple CommonJS spec implementation for PHP 5.3+.|url=https://github.com/DrBenton/CommonJSForPHP|access-date=2021-08-05|website=GitHub|language=en}}
  • CouchDB{{Cite web|title=Implementations/CouchDB - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/CouchDB|access-date=2021-08-05|website=wiki.commonjs.org}}
  • Flusspferd{{Cite web|url=https://flusspferd.github.com/|title=Flusspferd - CommonJS platform | Javascript bindings for C|access-date=2017-09-19|archive-date=2013-01-28|archive-url=https://web.archive.org/web/20130128180944/http://flusspferd.github.com/|url-status=dead}}
  • GPSEE{{Cite web|title=Implementations/GPSEE - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/GPSEE|access-date=2021-08-05|website=wiki.commonjs.org}}
  • Jetpack
  • Joyent Smart Platform{{Cite web|title=Implementations/Smart - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/Smart|access-date=2021-08-05|website=wiki.commonjs.org}}
  • JSBuild{{Cite web|url=http://jsbuild.kodfabrik.com|archiveurl=https://web.archive.org/web/20110104112332/http://jsbuild.kodfabrik.com/|url-status=dead|title=Homepage - JSBuild|archivedate=January 4, 2011}}
  • MongoDB{{Cite web|title=The most popular database for modern apps|url=https://www.mongodb.com/|access-date=2021-08-05|website=MongoDB|language=en-us}}
  • Narwhal (JavaScript platform){{Cite web|title=Implementations/Narwhal - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/Narwhal|access-date=2021-08-05|website=wiki.commonjs.org}}
  • Node.js (partial; synchronous){{Cite web|title=Implementations/node.js - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/node.js|access-date=2021-08-05|website=wiki.commonjs.org}}
  • Persevere{{Cite web|title=Implementations/Persevere - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/Persevere|access-date=2021-08-05|website=wiki.commonjs.org}}
  • PINF JavaScript Loader{{Cite web|title=GitHub - pinf/loader-js: EARLY STALLED EXPLORATION|url=https://github.com/pinf/loader-js|access-date=2021-08-05|website=GitHub|date=30 July 2021 |language=en}}
  • PythonMonkey implements a CommonJS Modules/1.1.1 environment which can load modules written in either JavaScript or Python (or both).{{cite web | title=Distributive-Network/PythonMonkey: A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment. | website=GitHub | date=2023-07-07 | url=https://github.com/Distributive-Network/PythonMonkey | ref={{sfnref | GitHub | 2023}} | access-date=2023-07-10}}
  • RingoJS{{Cite web|title=Implementations/RingoJS - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/RingoJS|access-date=2021-08-05|website=wiki.commonjs.org}}
  • SilkJS{{Cite web |url=http://silkjs.net/ |title=SilkJS WWW Site |access-date=2012-10-19 |archive-url=https://web.archive.org/web/20170912134815/http://silkjs.net/ |archive-date=2017-09-12 |url-status=dead }}
  • SproutCore{{Cite web|title=Implementations/SproutCore - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/SproutCore|access-date=2021-08-05|website=wiki.commonjs.org}}
  • TeaJS{{Cite web|title=Implementations/TeaJS - CommonJS Spec Wiki|url=http://wiki.commonjs.org/wiki/Implementations/TeaJS|access-date=2021-08-05|website=wiki.commonjs.org}}
  • Wakanda{{Cite web|last=SAS|first=Wakanda|title=Wakanda FullStack JavaScript Platform|url=https://wakanda.github.io/|access-date=2021-08-05|website=Wakanda FullStack JavaScript Platform|language=en}}
  • XULJet{{Cite web|title=Google Code Archive - Long-term storage for Google Code Project Hosting.|url=https://code.google.com/archive/p/xuljet|access-date=2021-08-05|website=code.google.com}}
  • QUnit

}}

See also

References

{{Reflist|3}}