Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsApr 28, 2026·3 min de lectura

Lowdb — Lightweight JSON Database for Node.js

A small, simple JSON file database powered by plain JavaScript objects, ideal for CLIs, small servers, and prototyping.

Introduction

Lowdb is a tiny local JSON database for Node.js, Electron, and browser environments. It reads and writes a plain JSON file, making it easy to inspect, version-control, and debug. When you need persistence without the overhead of a full database server, Lowdb fits in a single dependency.

What Lowdb Does

  • Persists JavaScript objects to a JSON file on disk automatically
  • Provides a synchronous and asynchronous API for reads and writes
  • Works in Node.js, Electron, and browsers via localStorage adapters
  • Supports custom adapters for alternative storage backends
  • Requires zero configuration beyond a file path and default data

Architecture Overview

Lowdb reads the entire JSON file into memory on startup and writes the whole file back on every mutation. The adapter pattern allows swapping the storage layer: JSONFile for Node.js, LocalStorage for browsers, or Memory for testing. Because the data lives in a plain object, any JavaScript operation works directly on it.

Self-Hosting & Configuration

  • Install from npm and import the preset matching your runtime
  • No server, daemon, or background process required
  • For Electron apps, point the file path to the user data directory
  • Use the Memory adapter in test suites to avoid file I/O
  • Pair with lodash for richer query and manipulation utilities if needed

Key Features

  • Entire database is a single readable JSON file
  • ESM-first with TypeScript types included
  • Adapters for file system, localStorage, and in-memory usage
  • Atomic writes prevent partial file corruption on crash
  • Under 200 lines of source code, easy to audit and extend

Comparison with Similar Tools

  • SQLite — full relational engine; Lowdb is simpler when you only need key-value or document storage
  • conf / configstore — focused on app settings; Lowdb handles arbitrary data models
  • LevelDB — binary key-value store with better performance; Lowdb trades speed for human-readable files
  • JSON Server — serves a REST API from a JSON file; Lowdb is an embedded library without HTTP

FAQ

Q: Is Lowdb suitable for production APIs? A: It works for low-traffic services or tools. For concurrent writes at scale, a proper database engine is a better fit.

Q: Does it support queries or indexes? A: There is no built-in query language. You use plain JavaScript array methods or lodash to filter and sort.

Q: What happens if the process crashes mid-write? A: Lowdb uses atomic file writes (write-to-temp then rename), so the file is never left in a partial state.

Q: Can multiple processes share the same db.json? A: Not safely. Lowdb is designed for single-process use. Use a database server for multi-process access.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados