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.
}
});