Events

Node.js is an event-driven system. When you are performing different tasks, different events are emitted. You need to understand those events and how to use them. Events are defined by different modules. For example process.on() is an event. You can also create and use your own events. See example:

var events = require('events');
var eventEmitter = new events.EventEmitter();

eventEmitter.on('bankrupt', function() {
    console.log('You are bankrupt');
});

var networth = -20000;
if (networth < 0) {
    eventEmitter.emit('bankrupt');
}

output:

You are bankrupt

If the networth is less than 0, this event emitter prints a message to the console.