app.post('/apple',(req,res)=>{ // logic of adding apple. if(req.session){ io.to(`user-${req.session['user'].id}`).emit("new-apple","Congratulations! New Apple Created!"); } res.json({updated:1}); }); io.on('connection', function (socket) { .... if(socket.request.session['user']){ socket.join(`user-${socket.request.session['user'].id}`); // One common way is to join the socket to a room named by the `user.id` or other group information. } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter