I am trying to follow the facade design pattern in a node.js application where I have on object that is used with the rest of the application called controller.js as the facade. The controller controls calls to objects user.js, animal.js, and house.js which are all separate files.
In controller.js I do
var housecontroller = require("./controllers/housecontroller");
...
I want to call something like controller.getHouse()
in another file (client). How do I make it so that I can do that and not have to call housecontroller.getHouse()
?
Each of my controllers are formatted as follows
module.exports = {
getHouse:function(){...},
...
}
I'm a bit confused on how to properly export things in order to get this to work. I import/export the controllers and their methods in controller.js as follows
module.exports = {
getHouse : housecontroller.getHouse,
...
};
I use only the house in the examples but it's implied I do the same for user and animal which all have several methods. In the client, I just import controller.js and use its methods.
var controller = require("./controller");
controller.getHouse();