low-json-db
v1.0.2
Published
A lightweight, zero-dependency, file-based document database for Node.js.
Readme
low-json-db
A lightweight, zero-dependency, file-based document database for Node.js.
It stores each collection as a plain JSON file and offers a familiar MongoDB-style API, with indexes, transactions, async support, and more.
Features
- Simple MongoDB-like API (
insert,find,update,delete, aggregation) - Atomic writes for crash safety
- Optional indexes (stored in separate
.idx.jsonfiles) - Sync + Async methods
- Transactions
- Auto ID generation (auto-increment, UUID, or ObjectId-style)
- Nested field support
- Import & Backup
- EventEmitter support
- TypeScript declarations included
- Zero dependencies
Installation
npm i low-json-dbOr just copy db.js (and optionally db.d.ts) into your project.
Quick Start
const { JSONDB } = require('low-json-db');
// or
const { JSONDB } = require('./db');
const db = new JSONDB('./data');
const users = db.collection({
name: 'users',
autoId: true,
indexes: ['email']
});
// Insert
const user = users.insert({
name: 'Alice',
email: '[email protected]',
age: 28
});
// Find
const found = users.findOne({ email: '[email protected]' });
// Update
users.updateOne(
{ name: 'Alice' },
{ $set: { age: 29 }, $push: { tags: 'admin' } }
);
// Async example
await users.insertAsync({ name: 'Bob', email: '[email protected]' });Documentation
Full documentation and examples:
https://amk2406.github.io/low-json-db
License
MIT
Contributing
Feel free to contribute! Open issues or pull requests on the repository.
Happy coding!
