I would like to know what is the correct way to pass the reference of the variable io to a class in Node.js
I currently have the variable initialized in a file index.js
:
const io = require('socket.io').listen(9000)
Reading some blogs I have observed that they only pass the variable to the constructor in this way:
class Foo{
constructor(io){
this.io = io
}
}
let objFoo = new Foo(io)
However, if it contains an object with active sockets inside it, the question is: Will the attribute io
of the class contain the connections (active sockets) that are made after the instantiation of the same? if not, is there any other way to refer to the variable io from another .js document (since the class is in another doc.)?