electron-store saves small JSON config blobs for Electron main or renderer processes with schema validation, optional encryption, and atomic writes.
Overview
electron-store fills the gap where Electron lacks built-in user settings persistence. It reads and writes a JSON config file under app.getPath('userData'), defaulting to config.json, and suits infrequently changing preferences rather than large databases.
The ESM-only API accepts defaults, JSON Schema validation through ajv, migrations keyed by semver, and optional AES encryption to deter casual hand-editing. Changes flush atomically to reduce corruption risk if a process crashes mid-write.
Store.initRenderer() or a main-process instance exposes data to renderers; importing directly in sandboxed renderers fails without IPC bridges because Node fs access is restricted. Requires Electron 35 or later.
Packaged Electron apps use it for window state, feature flags, and lightweight caches where SQLite would be heavier than necessary.
Key features
- Atomic JSON file writes
- JSON Schema validation
- Optional AES encryption
- Semver-based migrations
- Custom filename and cwd
- Defaults merged on read
- Main and renderer support
- Electron 35 plus requirement
Use cases
- Persist Electron window preferences
- Validate settings with JSON Schema
- Encrypt local config lightly
- Share settings over IPC from main