Node.js Authentication & JWT Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of the Node.js EventEmitter API, including creating emitters, registering listeners, emitting events, removing listeners, and handling event-driven programming.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. A mechanism for implementing event-driven communication
EventEmitter provides an event-driven mechanism where objects can emit named events and listeners can respond to them.
A. events
The built-in node:events module provides the EventEmitter class.
A. on()
The on() method registers a listener that is called whenever the specified event is emitted.
A. emit()
The emit() method synchronously calls the listeners registered for the specified event.
A. const { EventEmitter } = require('node:events');
CommonJS can import EventEmitter by destructuring it from the built-in node:events module.
A. const emitter = new EventEmitter();
EventEmitter is a class, so an instance can be created using the new keyword.
A. once()
The once() method registers a listener that is invoked at most once for the specified event.
A. The arguments are passed to the event listeners
Arguments supplied to emit() after the event name are passed to the registered listeners in the same order.
C. Both A and B
Node.js provides both off() and removeListener() for removing a previously registered listener.
A. The event whose registered listeners should be called
The event name identifies which listeners should be invoked when emit() is called.
A. If emitted without an error listener, Node.js throws the error and the process can terminate
The error event has special behavior. If no error listener is registered when an error event is emitted, Node.js treats it as an uncaught exception.
A. listenerCount()
The listenerCount() method returns the number of listeners currently registered for a specified event.
A. To remove listeners from an EventEmitter
removeAllListeners() removes all listeners, or all listeners for a specified event when an event name is provided.
A. Synchronously in the order they were registered
EventEmitter normally invokes listeners synchronously in the order they were registered.
A. It allows objects to emit named events and other code to listen for those events
EventEmitter is a general-purpose event-driven API used throughout Node.js for communicating through named events.