bar-db
raw JSON → 6.4.1 verified Fri May 01 auth: no javascript
Beyond All Reason Database (bar-db) is a lightweight, typed database library for Node.js and browser environments, currently at v6.4.1. It provides a simple key-value store with optional schema validation, focusing on ease of use and TypeScript integration. Key differentiators include zero dependencies, built-in JSON-based persistence, and support for async/await patterns. The library is actively maintained with a monthly release cadence.
Common errors
error TypeError: db.set is not a function ↓
cause Using require('bar-db') with v6 where only named ESM exports exist.
fix
Switch to import { Database } from 'bar-db' and ensure your project uses ESM.
error Error: ENOENT: no such file or directory, open './data.json' ↓
cause Database path is relative and the directory does not exist.
fix
Provide an absolute path or ensure the parent directory exists before init.
Warnings
breaking As of v6.0.0, all methods are async and return Promises. Sync API removed. ↓
fix Use await or .then() on all Database method calls. For sync usage, stick to v5.x.
breaking v6.0.0 removed the default export; use named exports instead. ↓
fix Replace `import Database from 'bar-db'` with `import { Database } from 'bar-db'`.
gotcha Database path is relative to process.cwd() in Node.js; always use an absolute path for consistency. ↓
fix Pass an absolute path or use path.resolve().
deprecated .save() and .load() methods are deprecated since v6.4.0. Use .init() for automatic persistence. ↓
fix Remove calls to .save() and .load(); .init() handles persistence automatically.
Install
npm install bar-db yarn add bar-db pnpm add bar-db Imports
- Database wrong
const Database = require('bar-db')correctimport { Database } from 'bar-db' - Schema
import { Schema } from 'bar-db' - type DBEntry
import type { DBEntry } from 'bar-db'
Quickstart
import { Database } from 'bar-db';
const db = new Database({ path: './data.json' });
await db.init();
// Insert a record
await db.set('user:1', { name: 'Alice', age: 30 });
// Retrieve a record
const user = await db.get('user:1');
console.log(user); // { name: 'Alice', age: 30 }
// Delete a record
await db.delete('user:1');
// List all keys
const keys = await db.keys();
console.log(keys); // []