I\'m having the following 3 files.
user.js requires room.js and room.js requires user.js.
user.js
var Room = require(\'./room.js\');
var Use
I think there is much better way how to do it. Just switch export and require like this:
user.js
var User = function () {};
module.exports = User;
User.prototype.test = function () {
return new Room();
};
var Room = require('./room.js');
room.js
var Room = function () {};
module.exports = Room;
Room.prototype.test = function () {
return new User();
};
var User = require('./user.js');
index.js
var User = require('./user.js');
var Room = require('./room.js');
var user = new User();
var room = new Room();
user.test();
room.test();
check this article: https://coderwall.com/p/myzvmg/circular-dependencies-in-node-js