{"id":24979,"library":"bar-db","title":"bar-db","description":"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.","status":"active","version":"6.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/Jazcash/bar-db","tags":["javascript","typescript"],"install":[{"cmd":"npm install bar-db","lang":"bash","label":"npm"},{"cmd":"yarn add bar-db","lang":"bash","label":"yarn"},{"cmd":"pnpm add bar-db","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v6. Requires Node >=12 or a bundler. TypeScript types included.","wrong":"const Database = require('bar-db')","symbol":"Database","correct":"import { Database } from 'bar-db'"},{"note":"Use for defining typed schemas. Not exported as default.","symbol":"Schema","correct":"import { Schema } from 'bar-db'"},{"note":"TypeScript users should import types explicitly for best tree-shaking.","symbol":"type DBEntry","correct":"import type { DBEntry } from 'bar-db'"}],"quickstart":{"code":"import { Database } from 'bar-db';\n\nconst db = new Database({ path: './data.json' });\nawait db.init();\n\n// Insert a record\nawait db.set('user:1', { name: 'Alice', age: 30 });\n\n// Retrieve a record\nconst user = await db.get('user:1');\nconsole.log(user); // { name: 'Alice', age: 30 }\n\n// Delete a record\nawait db.delete('user:1');\n\n// List all keys\nconst keys = await db.keys();\nconsole.log(keys); // []","lang":"typescript","description":"Initialize a bar-db database, insert, retrieve, delete a record, and list keys."},"warnings":[{"fix":"Use await or .then() on all Database method calls. For sync usage, stick to v5.x.","message":"As of v6.0.0, all methods are async and return Promises. Sync API removed.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Replace `import Database from 'bar-db'` with `import { Database } from 'bar-db'`.","message":"v6.0.0 removed the default export; use named exports instead.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Pass an absolute path or use path.resolve().","message":"Database path is relative to process.cwd() in Node.js; always use an absolute path for consistency.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Remove calls to .save() and .load(); .init() handles persistence automatically.","message":".save() and .load() methods are deprecated since v6.4.0. Use .init() for automatic persistence.","severity":"deprecated","affected_versions":">=6.4.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Switch to import { Database } from 'bar-db' and ensure your project uses ESM.","cause":"Using require('bar-db') with v6 where only named ESM exports exist.","error":"TypeError: db.set is not a function"},{"fix":"Provide an absolute path or ensure the parent directory exists before init.","cause":"Database path is relative and the directory does not exist.","error":"Error: ENOENT: no such file or directory, open './data.json'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}