Skip to content

Latest commit

 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlexiDB

GitHub GitHub last commit GitHub issues GitHub closed issues GitHub repo size npm downloads npm version Visitors

FlexiDB is a lightweight, flexible JSON-based database for Node.js projects. It offers async operations, atomic transactions, and zero dependencies, with direct file-based storage.

Features

  • File-Based Storage – All operations are performed directly on disk
  • 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

Installation

npm install flexi-db

Quick Example

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());
})();

API Overview

Core Methods

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)

Math Operations

Method Notes
add(key, number) Auto-converts non-numbers to 0
subtract(key, number) Subtract from number
math(key, operator, value) Supports +, -, *, /, %

Array Utilities

Method Description
push(key, val) Push value to array at given key

Advanced

Method Description
transaction([...]) Run multiple operations atomically
backup(fileName) Create a manual backup
reset() Clear all data
destroy() Save data and stop auto-backups

Options

You can pass options in the constructor:

new FlexiDB('file.json', {
  dataDir: 'data',      // default: 'FlexiDB'
  autoBackup: true      // default: false
});

File Structure

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

License

MIT – Free to use, modify, and distribute.

Contributing

Feel free to open issues or submit PRs. All contributions are welcome!

About

A lightweight, flexible JSON-based database designed for simplicity and performance. FlexiDB supports asynchronous operations, customizable data storage, automatic backups, and atomic transactions.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages