SQLite Embedded Database
Use SQLite as an embedded database for desktop apps, CLI tools, and edge deployments with zero configuration.
Overview
The library provides full SQLite3 feature support including transactions, user-defined functions, virtual tables, JSON operations, and WAL (Write-Ahead Logging) mode for concurrent read access. Unlike other SQLite bindings, better-sqlite3 uses a synchronous API which is actually faster in Node.js for SQLite operations since SQLite itself is synchronous and the async overhead adds latency.
SQLite has seen a renaissance with the rise of edge computing and local-first architectures. Tools like Turso (LibSQL), LiteFS, and Litestream enable SQLite replication and backups, making it viable for production workloads. better-sqlite3 supports in-memory databases for testing, WAL mode for multi-reader scenarios, and custom collation functions for locale-aware sorting.
Who Is This For?
- Embed a database in Electron or CLI applications
- Use SQLite for local-first web applications
- Run fast integration tests with in-memory SQLite
- Store configuration and metadata in serverless functions
Installation
npm install better-sqlite3 && npm install -D @types/better-sqlite3 Configuration
import Database from "better-sqlite3"
const db = new Database("app.db", { verbose: console.log })
db.pragma("journal_mode = WAL")
db.exec(`CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
)`)
const insert = db.prepare("INSERT INTO users (name, email) VALUES (?, ?)")
insert.run("John", "john@example.com") Explore AI Tools
Discover the best AI tools that complement your skills
Read AI & Design Articles
Tips and trends in the world of design and AI
Related Servers
Sentry Error Tracking
Monitor errors and performance issues in production with Sentry. AI agents can triage alerts and suggest fixes based on stack traces.
PostHog Product Analytics
Track product usage, manage feature flags, and analyze user behavior with PostHog, an open-source product analytics platform.
Database Query Builder
Generate and optimize SQL queries with AI assistance. Build complex queries, analyze execution plans, and improve database performance.