Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note that the NodeJS module mechanism is based on <a href="http://en.wikipedia.org/wiki/CommonJS" rel="noreferrer"><strong>CommonJS</strong></a> modules which are supported in many other implementations like <strong>RequireJS</strong>, but also <strong>SproutCore</strong>, <strong>CouchDB</strong>, <strong>Wakanda</strong>, <strong>OrientDB</strong>, <strong>ArangoDB</strong>, <strong>RingoJS</strong>, <strong>TeaJS</strong>, <strong>SilkJS</strong>, <strong>curl.js</strong>, or even <strong>Adobe Photoshop</strong> (via <a href="https://github.com/theiviaxx/PSLib" rel="noreferrer">PSLib</a>). You can find the full list of known implementations <a href="https://web.archive.org/web/20140803042801/http://www.commonjs.org/impl/" rel="noreferrer">here</a>.</p> <p>Unless your module use node specific features or module, I highly encourage you then using <code>exports</code> instead of <code>module.exports</code> <strong>which is not part of the CommonJS standard</strong>, and then mostly not supported by other implementations.</p> <p>Another NodeJS specific feature is when you assign a reference to a new object to <code>exports</code> instead of just adding properties and methods to it like in the last example provided by Jed Watson in this thread. I would personally discourage this practice as this <strong>breaks the circular reference support</strong> of the CommonJS modules mechanism. It is then not supported by all implementations and Jed example should then be written this way (or a similar one) to provide a more universal module:</p> <p>(sayhello.js):</p> <pre><code>exports.run = function() { console.log("Hello World!"); } </code></pre> <p>(app.js):</p> <pre><code>var sayHello = require('./sayhello'); sayHello.run(); // "Hello World!" </code></pre> <p>Or using ES6 features</p> <p>(sayhello.js):</p> <pre><code>Object.assign(exports, { // Put all your public API here sayhello() { console.log("Hello World!"); } }); </code></pre> <p>(app.js):</p> <pre><code>const { sayHello } = require('./sayhello'); sayHello(); // "Hello World!" </code></pre> <p>PS: It looks like Appcelerator also implements CommonJS modules, but without the circular reference support (see: <a href="https://stackoverflow.com/questions/10859630/appcelerator-and-commonjs-modules-caching-and-circular-references">Appcelerator and CommonJS modules (caching and circular references)</a>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload