So I have a message board (my first MERN project,) and I'm trying to implement a notification feature using socket.io. Overkill I know, but I plan to expand it to include a simple chat room later.
I'm wondering if somebody would (please) explain to me how I can associate a user with a connection so that I can send a message from the server to a specific user.
Server:
io.on('connection', (socket) => {
socket.emit('messageFromServer', { data: 'Welcome to the server' });
socket.on('messageToServer', (dataFromClient) => {
console.log(dataFromClient);
});
});
client:
socket.on('messageFromServer', (data) => {
console.log(data);
});
socket.emit('messageToServer', { username: appState.username });