0
0
Expressframework~10 mins

Socket.io integration with Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Socket.io library.

Express
const express = require('express');
const http = require('http');
const socketIo = require('[1]');
Drag options to blanks, or click blank then click option'
Asocket.io-client
Bexpress-socket
Csocket.io
Dsocket
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'socket.io-client' instead of 'socket.io'.
Using a wrong package name like 'socket'.
2fill in blank
medium

Complete the code to create an HTTP server from the Express app.

Express
const app = express();
const server = http.createServer([1]);
Drag options to blanks, or click blank then click option'
AsocketIo
Bhttp
Cexpress
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the Socket.io instance instead of the Express app.
Passing the HTTP module itself.
3fill in blank
hard

Fix the error in initializing Socket.io with the HTTP server.

Express
const io = socketIo([1]);
Drag options to blanks, or click blank then click option'
Aserver
Bapp
Chttp
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the Express app instead of the HTTP server.
Passing the HTTP module or express module.
4fill in blank
hard

Fill both blanks to listen for a new client connection and log a message.

Express
io.on('[1]', (socket) => {
  console.log('A client [2]');
});
Drag options to blanks, or click blank then click option'
Aconnection
Bdisconnect
Cconnected
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' or 'connected' as event name instead of 'connection'.
Using 'disconnect' event here.
5fill in blank
hard

Fill all three blanks to emit a message to the client when connected.

Express
io.on('connection', ([1]) => {
  [2].[3]('welcome', 'Hello from server!');
});
Drag options to blanks, or click blank then click option'
Asocket
Bemit
Csend
Dconnection
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'emit' to send events.
Using wrong parameter name instead of 'socket'.