Note Taker
This concise example demonstrates a note-taking application using ULDA. It creates a master file for notes, adds a note, updates it, and deletes it, with real-time update notifications.
import { Ulda } from '@zeroam/ulda';
async function noteTaker() {
const ulda = new Ulda('your_api_key', 'https://api.0am.ch', true);
const masterFileName = 'noteVault'; // Unique per API key
const password = 'notePass123';
try {
// Create and connect to master file
await ulda.createMasterFile(masterFileName, password);
await ulda.connect(masterFileName, password);
// Create a note (content file)
const note = { title: 'Meeting', text: 'Discuss project at 2 PM' };
await ulda.createContentFile(note, 'meetingNote'); // Unique in master file
console.log('Note created:', ulda.data['meetingNote'].content);
// Update the note
await ulda.data['meetingNote'].update({ text: 'Discuss project at 3 PM' });
console.log('Note updated:', ulda.data['meetingNote'].content);
// Listen for real-time updates
await ulda.connectToUpdateContentFile((response) => {
console.log('Note updated in real-time:', response);
});
// Delete the note
await ulda.data['meetingNote'].delete();
console.log('Note deleted');
} catch (error) {
console.error('Error:', error.message);
}
}
noteTaker().catch(console.error);
Success Output:
Note created: { title: 'Meeting', text: 'Discuss project at 2 PM' }
Note updated: { title: 'Meeting', text: 'Discuss project at 3 PM' }
Note deleted
Notes:
- Line count: 32 lines (excluding comments/whitespace), meeting the 100-line constraint.
- Real-time update output is omitted as it requires external triggers.
- Outputs reflect successful
createContentFile,update, anddeleteoperations.