I'm building my first MERN app [a message board] and trying to add a mail notification using socket.io.
So far I have in server.js:
const io = socketio(expressServer);
const connectedUsers = {};
io.on('connection', (socket) => {
socket.emit('messageFromServer', { data: 'Welcome to the server' });
socket.on('messageToServer', (dataFromClient) => {
connectedUsers[dataFromClient.username] = socket;
});
});
to emit from my controller file, do I need the io object or just the socket, and how can I share it/them with the controller file?
All help greatly appreciated!