0
0
Node.jsframework~10 mins

Why the event system matters in Node.js - Test Your Understanding

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

Complete the code to import the EventEmitter class from the 'events' module.

Node.js
const [1] = require('events');
Drag options to blanks, or click blank then click option'
AEventEmitter
BEmitter
CEvent
DEmitterClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name like 'Emitter' or 'Event'.
Forgetting to import the class before using it.
2fill in blank
medium

Complete the code to create a new instance of EventEmitter.

Node.js
const emitter = new [1]();
Drag options to blanks, or click blank then click option'
AEventEmitter
BEmitter
CEvent
DEmitterClass
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to instantiate a wrong or undefined class.
Using lowercase or misspelled class names.
3fill in blank
hard

Fix the error in the code to listen for the 'message' event.

Node.js
emitter.[1]('message', () => {
  console.log('Message received');
});
Drag options to blanks, or click blank then click option'
Alisten
BaddListenerEvent
ConMessage
Don
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'listen' or 'onMessage'.
Confusing event registration with event emitting.
4fill in blank
hard

Fill both blanks to emit a 'data' event with a payload.

Node.js
emitter.[1]('[2]', { id: 1, value: 'hello' });
Drag options to blanks, or click blank then click option'
Aemit
Bdata
Csend
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'emit' to trigger events.
Using wrong event names that don't match listeners.
5fill in blank
hard

Fill all three blanks to create a listener for 'update' event that logs the payload's status.

Node.js
emitter.[1]('[2]', (payload) => {
  console.log('Status:', payload.[3]);
});
Drag options to blanks, or click blank then click option'
Aon
Bupdate
Cstatus
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' instead of 'on' to listen for events.
Using wrong event names or property names.