Localbase: Offline Firebase-Style Database

0.7.7 · active · verified Wed Apr 22

Localbase is a JavaScript library providing a Firebase Cloud Firestore-like API for an offline, browser-based database powered by IndexedDB. It simplifies local data persistence, allowing developers to manage data in collections and documents without direct interaction with the complexities of IndexedDB. The current stable version is 0.7.7. Releases appear somewhat irregularly, primarily addressing bug fixes, compatibility issues (e.g., Vite environment), and new features like collection filtering. Its key differentiators include its familiar API for developers accustomed to Firebase, robust offline capabilities, and its foundation on LocalForage, which handles cross-browser IndexedDB inconsistencies. It also ships with TypeScript type definitions for improved developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize Localbase, add a new document to a collection, update an existing document, and retrieve data from a collection and a specific document using async/await.

import Localbase from 'localbase'

const db = new Localbase('my-app-db')

async function manageData() {
  // Add a document
  await db.collection('users').add({
    id: 'user123',
    name: 'Alice',
    email: 'alice@example.com'
  })
  console.log('Added Alice.')

  // Update a document
  await db.collection('users').doc('user123').update({
    email: 'alice.updated@example.com'
  })
  console.log('Updated Alice\'s email.')

  // Get all documents in a collection
  const users = await db.collection('users').get()
  console.log('Current users:', users)

  // Get a specific document
  const alice = await db.collection('users').doc('user123').get()
  console.log('Alice data:', alice)
}

manageData().catch(console.error)

view raw JSON →