Loopback has several standard events including "started" and "stopping". But you are not limited to just these events. You can create your own events as well.
Publishing a Custom Event
In an App Behavior or Business Object Behavior, you can publish an event like this:
this.app.emit('My Custom Event');
You can also send data along with the event:
this.app.emit('My Custom Event With Data', { blah: 'asdf' } );
Respond to a Custom Event
In an App Behavior or Business Object Behavior, you can respond to a custom event like this:
this.app.on('My Custom Event', async ()=>{
debug('My Custom Event happened!');
});
If the event includes data, you can handle it like this:
this.app.on('My Custom Event', async (data:any)=>{
debug('My Custom Event send me', data);
});
Only Within a Single Node
Remember that these events are only within a single node. If you need to manage events across multiple nodes in a cluster, you can check out the Socket Io Library.