A robust, atomic, and encrypted JSON store for Node.js.
Zero setup. TypeScript ready. O(1) Performance.
const JSONDatabase = require('json-database-st');
// Initialize with Schema Validation & Encryption
const db = new JSONDatabase('./data.json', {
encryptionKey: process.env.SECRET_KEY,
indices: [{ name: 'email', path: 'users', field: 'email' }]
});
// Atomic Write (Thread-safe)
await db.set('users.alice', {
id: 1,
email: 'alice@dev.com',
balance: 0
});
// Mathematical Operation (New in v2.0)
await db.add('users.alice.balance', 100);
// O(1) Instant Lookup via Hash Map
const user = await db.findByIndex('email', 'alice@dev.com');
Built-in AES-256-GCM encryption. Keep sensitive user data secure on disk without complex external logic.
Define indices on fields like `email` or `id`. Retrieve records instantly without scanning the entire file.
Uses `proper-lockfile` and atomic renaming strategies to prevent data corruption during crashes or concurrent writes.