// If an EventEmitter does not have at least one listener // registered for the 'error' event, and an 'error' event // is emitted, the error is thrown, a stack trace is printed, // and the Node.js process exits. const myEmitter = new MyEmitter(); myEmitter.emit('error', new Error('whoops!')); // Throws and crashes Node.js
Here is what the above code is Doing:
1. Create a new instance of MyEmitter.
2. Emit an ‘error’ event on that instance.
3. Because there are no listeners registered for the ‘error’ event, the error is thrown.