Lifecycle Hooks
Implementing application lifecycle hooks with the Node.js SDK.
Overview
Lifecycle hooks allow your application to respond to state changes:
onCreate- Process starts (before AppServer connection)onStartUp- AppServer connection establishedonRegister- App declares manifestonInstall- App is being installedonUninstall- App is being removedonDestroy- Process is shutting down
onCreate
Called when the application process starts, before connecting to AppServer.
TODO: Add onCreate hook details and examples
Use Cases
- Initialize global state
- Set up logging
- Validate environment variables
Example
onCreate: async (context) => {
console.log('App process starting...');
// Initialize services
}
onStartUp
Called after connection to AppServer is established.
TODO: Add onStartUp hook details and examples
Use Cases
- Connect to database
- Initialize caches
- Start background jobs
onRegister
Called when the app registers with AppServer. Must return the app manifest.
TODO: Add onRegister hook details and examples
Example
onRegister: async (context) => {
return {
id: 'my-app',
name: 'My Application',
version: '1.0.0',
dependencies: {
hard: [],
soft: []
},
permissions: {
required: [],
exposed: []
}
};
}
onInstall
Called when the app is being installed.
TODO: Add onInstall hook details and examples
Use Cases
- Run database migrations
- Create initial data
- Set up resources
Example
onInstall: async (context) => {
// Run migrations
await context.db.migrate();
// Create initial data
await createDefaultSettings(context);
}
onUninstall
Called when the app is being removed.
TODO: Add onUninstall hook details and examples
Use Cases
- Clean up resources
- Export data
- Remove temporary files
onDestroy
Called when the process is shutting down.
TODO: Add onDestroy hook details and examples
Use Cases
- Close database connections
- Flush logs
- Clean up gracefully
Error Handling
TODO: Document error handling in hooks:
- Throwing errors from hooks
- Retry behavior
- Failed state handling
Async Hooks
All hooks are async and can return promises.
Hook Execution Order
TODO: Add diagram showing hook execution flow