I am creating a simple animal.js module which extend in color.js module and output in app.js.
Animal.js:
var exports = module.exports = {};
exports.animalName = function() {
        console.log('Animal Name: Dog');
}
Color.js: Here I am extending the module animal.js and using it as a method of Color module i:e pAnimal();
var animal = require('./animal.js');
exports.animalColor = function() {
        console.log('Color is Black');
        function pAnimal() {
                var pAnimal = animal;
                pAnimal.animalName;
        }
}
App.js: Here I am trying to get value from color module as //Animal Name: Dog & //Color is Black
var localAnimal = require('./color.js');
localAnimal.animalColor();
localAnimal.animalColor.pAnimal();
But when I run this in node server I get error like this:
    D:\node\module-extend>node app.js
    Color is Black
    D:\node\module-extend\app.js:4
    localAnimal.animalColor.pAnimal();
                        ^
TypeError: localAnimal.animalColor.pAnimal is not a function
    at Object.<anonymous> (D:\node\module-extend\app.js:4:25)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Please help. Thanks
 
     
     
    