Event
NocoBase's server triggers corresponding events during application lifecycle, plugin lifecycle, and database operations. You can listen to these events to implement extension logic, automated operations, or custom behaviors.
NocoBase's event system is mainly divided into two levels:
app.on()-- Application Level Events: Listen to application lifecycle events, such as startup, installation, enabling plugins, etc.db.on()-- Database Level Events: Listen to data model level operation events, such as creating, updating, deleting records, etc.
Both inherit from Node.js's EventEmitter, supporting standard .on(), .off(), .emit() interfaces. NocoBase also extends emitAsync, used to asynchronously trigger events and wait for all listeners to complete execution.
Where to Register Event Listeners
Event listeners are typically registered in the plugin's beforeLoad() method, ensuring events are ready during the plugin loading phase, and subsequent logic can respond correctly.
Listen to Application Events app.on()
Application events are used to capture NocoBase application and plugin lifecycle changes, suitable for initialization logic, resource registration, or dependency detection.
Common Event Types
Example: Listen to application startup event
Example: Listen to plugin load event
Listen to Database Events db.on()
Database events capture various data changes at the model level, suitable for auditing, synchronization, auto-filling, and other operations.
Common Event Types
Example: Listen for the event after data creation
Example: Listen for the event before data update
Related Links
- Plugin — Register event listeners in plugin lifecycle methods
- Database — Database-level event sources and data operation APIs
- Collections — Collection definitions and model relationships in database events
- Middleware — Collaboration between middleware and events in request processing
- Server Development Overview — The role of the event system in server architecture

