FlexiDB is a lightweight, flexible JSON-based database for Node.js projects. It offers in-memory caching, async operations, atomic transactions, and zero dependencies.
- ⚡ High Performance – In-memory caching and debounced disk writes
- 🔄 Async API – All methods are promise-based
- 💾 Custom Storage – Use any directory for data and backups
- 🔁 Auto Backups – Optional periodic file backups
- 🔒 Atomic Transactions – Grouped operations with rollback
- 🨠 Type Safety – Auto conversion for numeric operations
- 🪦 Zero Dependencies – Uses Node.js core only
npm install flexi-db
const FlexiDB = require('flexi-db');
const db = new FlexiDB('mydb.json', { dataDir: 'data', autoBackup: true });
(async () => {
await db.set('user1', { name: 'Ali', age: 25 });
await db.add('score', 10);
await db.push('items', 'apple');
await db.transaction([
{ type: 'set', key: 'user2', value: { name: 'Sara' } },
{ type: 'add', key: 'score', value: 5 }
]);
console.log(db.all());
})();
Method | Description |
---|---|
set(key, value) |
Store a value |
get(key) |
Retrieve a value |
has(key) |
Check key existence |
delete(key) |
Remove a key |
all(limit?) |
Get all key-value pairs (optional limit) |
Method | Notes |
---|---|
add(key, number) |
Auto-converts non-numbers to 0 |
subtract(key, number) |
Subtract from number |
math(key, operator, value) |
Supports + , - , * , / , %
|
Method | Description |
---|---|
push(key, val) |
Push value to array at given key |
Method | Description |
---|---|
transaction([...]) |
Run multiple operations atomically |
backup(fileName) |
Create a manual backup |
reset() |
Clear all data |
destroy() |
Save data and stop auto-backups |
You can pass options in the constructor:
new FlexiDB('file.json', {
dataDir: 'data', // default: 'FlexiDB'
autoBackup: true // default: false
});
All data and backups are stored in the specified dataDir
, helping you keep your project organized.
my-project/
└── data/ # or 'FlexiDB' by default
├── mydb.json
└── backup-2025.json
MIT – Free to use, modify, and distribute.
Feel free to open issues or submit PRs. All contributions are welcome!