Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Data Persistence – e | Electron.js Desktop App Development l | BraveProgrammer
  1. Courses
  2. /
  3. Electron.js Desktop App Development

Lesson 11 of 28

·javascript

Data Persistence – electron-store, SQLite & LowDB

11 mins

Course progress39%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `electron-store` offers a simple key/value store with automatic JSON serialization.
  • SQLite provides a powerful relational DB – use `better-sqlite3` for synchronous API or `sqlite3` for async.
  • `lowdb` is a tiny JSON‑file DB useful for prototypes or settings.
  • All persistence logic should stay in the **main** process for security.

Data Persistence – electron-store, SQLite & LowDB

electron-store (key/value JSON)

npm install electron-store
const Store = require('electron-store');
const store = new Store();
store.set('settings.theme', 'dark');
console.log(store.get('settings.theme'));

Data is saved in a plain JSON file inside app.getPath('userData').

SQLite (via better‑sqlite3)

npm install better-sqlite3
const Database = require('better-sqlite3');
const db = new Database(path.join(app.getPath('userData'), 'app.db'));
db.exec('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, title TEXT, body TEXT)');
function addNote(title, body){
  const stmt = db.prepare('INSERT INTO notes (title, body) VALUES (?, ?)');
  return stmt.run(title, body).lastInsertRowid;
}

SQLite is great for relational data and fast queries.

LowDB (tiny JSON database)

npm install lowdb
const { Low, JSONFile } = require('lowdb');
const adapter = new JSONFile(path.join(app.getPath('userData'), 'db.json'));
const db = new Low(adapter);
await db.read();
db.data ||= { notes: [] };
db.data.notes.push({ id: Date.now(), text: 'Hello' });
await db.write();

LowDB is perfect for small prototype apps.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Electron.js Desktop App DevelopmentBrowse activities
Previous lessonState Management Across ProcessesContinue to lesson 12Installing Node, npm & ElectronBack to Electron.js Desktop App Development curriculum