Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://nodejs.org/api/modules.html#modules_module_exports" rel="noreferrer"><code>module.exports</code></a> is the object that's actually returned as the result of a <code>require</code> call.</p> <p>The <code>exports</code> variable is initially set to that same object (i.e. it's a shorthand "alias"), so in the module code you would usually write something like this:</p> <pre><code>var myFunc1 = function() { ... }; var myFunc2 = function() { ... }; exports.myFunc1 = myFunc1; exports.myFunc2 = myFunc2; </code></pre> <p>to export (or "expose") the internally scoped functions <code>myFunc1</code> and <code>myFunc2</code>.</p> <p>And in the calling code you would use:</p> <pre><code>var m = require('./mymodule'); m.myFunc1(); </code></pre> <p>where the last line shows how the result of <code>require</code> is (usually) just a plain object whose properties may be accessed.</p> <p>NB: if you overwrite <code>exports</code> then it will no longer refer to <code>module.exports</code>. So if you wish to assign a new object (or a function reference) to <code>exports</code> then you should also assign that new object to <code>module.exports</code></p> <hr> <p>It's worth noting that the name added to the <code>exports</code> object does not have to be the same as the module's internally scoped name for the value that you're adding, so you could have:</p> <pre><code>var myVeryLongInternalName = function() { ... }; exports.shortName = myVeryLongInternalName; // add other objects, functions, as required </code></pre> <p>followed by:</p> <pre><code>var m = require('./mymodule'); m.shortName(); // invokes module.myVeryLongInternalName </code></pre>
    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. 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.
 

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