I am getting error like I have shown in question I am using this answer as solution but i got the error
this is code of app.js
const server = require('http').createServer(app);
const io = require('socket.io')(server);
io.on('connection', async (socket) => {
console.log('socket connected', userId)
if (io.nsps['/'].adapter.rooms["room-" + userId] && io.nsps['/'].adapter.rooms["room-" + userId].length > 0) userId++;
socket.join("room-" + userId);
io.sockets.in("room-" + userId).emit('connectToRoom', "You are in room no. " + userId);
io.sockets.in("room-" + userId).emit('Image upload', "image upload is started");
io.sockets.in("room-" + userId).emit('progress', "Image is Uploading started Please Wait A minute");
io.sockets.in("room-" + userId).emit('error', "clients connected!");
});
function getSocketIo() {
return io;
}
module.exports.getSocketIo = getSocketIo();
this is the code of controller file where I am importing getSocketIo
but got error
const getSocketIo = require('../app.js');
const io = app.getSocketIo()
^
|------------ error - Uncaught TypeError: app.getSocketIo is not a function in socket.io