code Fungsi addNote
// Konfigurasi file
const FILE_NAME = "notes.txt";
// CREATE - Tambah catatan
async function addNote(content: string) {
const file = Bun.file(FILE_NAME);
const existing = (await file.exists()) ? await file.text() : "";
const timestamp = new Date().toLocaleString();
const note = `[${timestamp}] ${content}\n`;
await Bun.write(FILE_NAME, existing + note);
console.log("✅ Catatan berhasil ditambahkan");
}
const FILE_NAME = "notes.txt";
// CREATE - Tambah catatan
async function addNote(content: string) {
const file = Bun.file(FILE_NAME);
const existing = (await file.exists()) ? await file.text() : "";
const timestamp = new Date().toLocaleString();
const note = `[${timestamp}] ${content}\n`;
await Bun.write(FILE_NAME, existing + note);
console.log("✅ Catatan berhasil ditambahkan");
}
File Handling
Membuka file notes.txt, membuat file baru jika belum ada
Timestamp
Menambahkan waktu otomatis untuk setiap catatan
Format Catatan
Format: [waktu] isi catatan
bun run index.ts "Belajar Bun"