0
0
Expressframework~5 mins

Setting up WebSocket server in Express - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is a WebSocket server?
A WebSocket server allows real-time, two-way communication between a client and server over a single, long-lived connection.
Click to reveal answer
beginner
Which Node.js package is commonly used to add WebSocket support to an Express server?
The 'ws' package is commonly used to add WebSocket support to an Express server.
Click to reveal answer
intermediate
How do you create a WebSocket server that works alongside an Express app?
You create an HTTP server from the Express app, then attach the WebSocket server to that HTTP server.
Click to reveal answer
beginner
What event do you listen for to handle new WebSocket connections?
You listen for the 'connection' event on the WebSocket server to handle new client connections.
Click to reveal answer
intermediate
Why is it important to handle errors and close events on WebSocket connections?
Handling errors and close events helps keep the server stable and frees resources when clients disconnect.
Click to reveal answer
Which method creates an HTTP server from an Express app to use with WebSocket?
Aws.createServer(app)
Bexpress.createServer()
Chttp.createServer(app)
Dapp.listenWebSocket()
Which event do you listen to on a WebSocket server to accept new clients?
Aconnect
Bconnection
Copen
Dstart
What package do you install to add WebSocket support in an Express app?
Aws
Bwebsocket-express
Cexpress-ws
Dsocket.io
How do you send a message to a connected WebSocket client?
Aclient.send('message')
Bclient.emit('message')
Cclient.write('message')
Dclient.push('message')
Why should you handle the 'close' event on a WebSocket connection?
ATo restart the server
BTo block the client
CTo send a welcome message
DTo free resources and clean up
Explain the steps to set up a WebSocket server alongside an Express app.
Think about how Express and WebSocket share the same HTTP server.
You got /5 concepts.
    Describe why WebSocket is useful compared to regular HTTP requests.
    Imagine chatting live versus sending letters.
    You got /4 concepts.