How does “Exports” work in Node JS

יום רביעי, ינואר 1, 2014

If you wandered how does “NodeJS exports” works under the covers here in the answer. The trick is simple: wrap your function (object definition) with a wrapper function that accepts the exports object from the global scope. This makes exports global, allows you to attach your code to it and prevents your code from reaching the global scope. Code Snippet //wrapper function (function (exports, require, module, __filename, __dirname) {     //your code     var calculator = function() {         return {             add: function(a, b) { return a + b; }         };     };     exports.add = calculator; }); ...
no comments

How does “Exports” work in Node JS

If you wandered how does exports works under the covers here in the answer. The trick is simple: wrap your function (object definition) with a wrapper function that accepts the exports object from the global scope. This makes exports global, allows you to attach your code to it and prevents your code from reaching the global scope. 1: //wrapper function 2: (function (exports, require, module, __filename, __dirname) { 3: //your code 4: var calculator = function() { 5: ...
no comments