Utilities
In the next group of modules, we will look at utilities. The functions chosen here are used across many different types of applications. We will cover everything from events and cryptology to buffers and npm.
Events
Events are used in many built-in Node objects. This is because emitting and listening for events is the perfect way to let another function know when to start executing. This is especially true in the asynchronous world of Node.js. Anytime we use the on function of an object, it means that it has inherited from EventEmitter. All of the examples will assume that the events variable is already created as follows:
var events = require('events');EventEmitter
This is the parent class that can be inherited from to create a new EventEmitter:
events.EventEmitter
Description
Node.js has a fully featured event system that we can easily inherit from and implement. We do not need any extra frameworks or custom code. EventEmitter is the class to inherit from, and we will get...