When the user connects, join them to a personal room: socket.join('user:' + userId). To send a notification from a route handler: io.of('/notifications').to('user:' + userId).emit('notification', data). Only that user receives the notification.
How do I send a notification to a specific user?
More FAQs in Socket.io Namespaces and Rooms Organizing Connections in Node.js
Namespaces are top-level channels that separate features (chat, admin, notifications), each with its own auth and events. Rooms are sub-groups within a namespace for grouping users (chat rooms, group chats). Use namespaces for feature separation, rooms for user grouping.
Use io.of('/namespace-name'): const adminNsp = io.of('/admin'). Add namespace-specific middleware with adminNsp.use() and handle events with adminNsp.on('connection', ...). The client connects to the namespace with io('url/admin', { auth: { token } }).
Use namespaces to separate features with different auth requirements or event sets: chat (default /), admin dashboard (/admin with admin-only auth), notifications (/notifications for push notifications), live updates (/live for data feeds). Each namespace has its own middleware and event handlers.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.