Page Contents

The LoopBack app object is a Node EventEmitter, and thus has app.emit() and app.on() methods.

In addition to the standard Node events, LoopBack applications and models emit other events.

Application events

By default, an application created with the application generator emits a ‘started’ event when it starts up, after running boot scripts.

Model events

All models emit the following events:

By default, the basic LoopBack Model object has properties and methods “mixed in” from:

When you define relations between models, the RelationMixin object object also gets mixed in to the model object.

attached

Emitted after a Model has been attached to an app.

dataSourceAttached

Emitted after a Model has been attached to a DataSource.

set

Emitted when model property is set. Argument: inst, model instance, object.

For example:

MyModel.on('set', function(inst) {
  console.log('model with id %s has been changed', inst.id);
  // => model with id 1 has been changed
});

Arguments: data, an object.

User model events

The User model User.resetPassword() method emits the ’resetPasswordRequest’ event.