🗄️
Database1.5M+/wkMIT

better-sqlite3

better-sqlite3 is the fastest and simplest SQLite3 library for Node.js, providing a synchronous API that is significantly faster than asynchronous alternatives

Installation

npm
npm install better-sqlite3
yarn
yarn add better-sqlite3
pnpm
pnpm add better-sqlite3

Import

ESM
import Database from 'better-sqlite3';

Quick Example

usage
import Database from 'better-sqlite3';

const db = new Database('mydb.sqlite');

db.exec(`CREATE TABLE IF NOT EXISTS users (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL
)`);

const insert = db.prepare('INSERT INTO users (name) VALUES (?)');
insert.run('Alice');

const user = db.prepare('SELECT * FROM users WHERE name = ?').get('Alice');

About better-sqlite3

better-sqlite3 is the fastest and simplest SQLite3 library for Node.js, providing a synchronous API that is significantly faster than asynchronous alternatives for typical database workloads. Unlike other SQLite bindings that wrap every operation in asynchronous callbacks or promises, better-sqlite3 leverages the fact that SQLite operations on a local database file complete in microseconds, making the overhead of async wrapping counterproductive. The synchronous API is simpler to use and easier to reason about: const row = db.prepare('SELECT * FROM users WHERE id = ?').get(id). The library supports transactions (which are automatically rolled back on error), user-defined functions (scalar, aggregate, and table-valued), virtual tables, WAL mode for concurrent reading, and backup operations. better-sqlite3 uses N-API for native bindings, ensuring stability across Node.js versions. The library pre-compiles statements for repeated execution, supports parameter binding for SQL injection prevention, and provides iterator-based result streaming for large queries. better-sqlite3 is the SQLite driver used by Drizzle ORM and is popular for local databases, embedded applications, testing, and serverless functions where a file-based database eliminates the need for external database services.

Quick Facts

Packagebetter-sqlite3
CategoryDatabase
Weekly Downloads1.5M+
LicenseMIT
Installnpm install better-sqlite3

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.