Cannot find function of undefined - CommonJS pattern

var revealed = function(){
   var a = [1,2,3];
   function abc(){
     return (a[0]*a[1])+a[2]);
   }

   return {
      name: 'revealed',
      abcfn: abc
   }

   module.exports = revealed;
}();

How can i use CommonJS pattern with Revealing Module pattern?. When i try to do module.exports = revealed; and try to include the module somewhere to call the function, it throws me error saying function not found.

var module = require('module');
module.abc();

Cannot call method of undefined.

You are returning the object before assigning to module.exports!

What you want is this:

var revealed = function(){
   var a = [1,2,3];
   function abc(){
     return (a[0]*a[1])+a[2]);
   }

   return {
      name: 'revealed',
      abcfn: abc
   }
}();

module.exports = revealed;

Inside your module function, revealed isn't defined.

What you might do is this :

var revealed = function(){
   var a = [1,2,3];
   function abc(){
     return (a[0]*a[1])+a[2]);
   }

   return module.exports = {
      name: 'revealed',
      abcfn: abc
   }
}();