Complete the code to import the Socket.io library in a Node.js server.
const io = require('[1]');
The Socket.io library is imported using require('socket.io') in Node.js.
Complete the code to create a new Socket.io server attached to an HTTP server.
const io = require('socket.io')( [1] );
The Socket.io server is attached to the HTTP server instance, usually named server.
Fix the error in the code to listen for new client connections.
io.on('[1]', (socket) => { console.log('A user connected'); });
The correct event name to listen for new connections is 'connection'.
Fill both blanks to emit a message to all connected clients except the sender.
socket.[1].emit('[2]', 'Hello everyone except me');
To send a message to all clients except the sender, use socket.broadcast.emit('message', ...).
Fill all three blanks to listen for a custom event and respond to the sender.
socket.on('[1]', (data) => { console.log('Received:', data); socket.[2]('[3]', 'Got your message'); });
The code listens for the 'chat message' event, then uses socket.emit to send a 'reply' event back to the sender.