all.db: Simple JSON Database

0.3.2 · maintenance · verified Wed Apr 22

all.db is a lightweight, file-based JSON database designed for simple data persistence in Node.js applications. It stores data as a single JSON file on the local filesystem, providing a straightforward key-value store interface. Currently at version 0.3.2, its release cadence appears slow, with the last notable activity several years ago, suggesting it is in a maintenance phase rather than active development. Key differentiators include its extreme simplicity, minimal API (set, get, delete), and built-in TypeScript type definitions. Unlike more robust databases, it is not designed for high-concurrency environments or very large datasets due to its synchronous file operations, which can block the event loop, and its approach of loading the entire database into memory. It's best suited for small-scale projects, local development, or simple configuration storage.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize `all.db`, store and retrieve various types of data (including typed objects), update values, and delete entries. It also includes basic directory creation for the database file.

import { Database } from 'all.db';
import * as path from 'path';
import * as fs from 'fs';

// Ensure the directory exists, or create it
const dbDir = path.join(process.cwd(), 'data');
if (!fs.existsSync(dbDir)) {
  fs.mkdirSync(dbDir, { recursive: true });
}

const db = new Database(path.join(dbDir, 'my-app-data.json'));

interface User {
  id: string;
  name: string;
  email: string;
}

async function runExample() {
  // Set data
  db.set('settings', { theme: 'dark', notifications: true });
  db.set<User>('user:123', { id: '123', name: 'Alice', email: 'alice@example.com' });
  db.set('lastLogin', new Date().toISOString());

  // Get data
  const settings = db.get('settings');
  console.log('Settings:', settings);

  const alice = db.get<User>('user:123');
  console.log('Alice:', alice);

  // Update data
  if (settings) {
    settings.notifications = false;
    db.set('settings', settings);
  }
  console.log('Updated settings:', db.get('settings'));

  // Delete data
  db.delete('lastLogin');
  console.log('Last login after delete:', db.get('lastLogin'));

  // Check if a key exists
  console.log('Does user:123 exist?', db.has('user:123'));
  console.log('All data:', db.all());
}

runExample().catch(console.error);

view raw JSON →