---
name: node-sqlite
description: "Node.js now has a built-in SQLite database, node:sqlite, with no npm dependency. Use whenever a Node.js task needs a database that runs in-process: SQLite, a local, embedded or in-memory database, or app/CLI storage; safe parameterized SQL that prevents SQL injection; running untrusted SQL; or would otherwise reach for better-sqlite3 or sqlite3. Covers Database/Statement (DatabaseSync and StatementSync are deprecated aliases), createTagStore tagged-template SQL, setAuthorizer, defensive mode (on by default), limits, serialize/deserialize, createModule virtual tables, statement.close/stat and using. Node.js 24+; some parts need 24.22+ or 26.x."
title: node-sqlite
canonical_url: https://skilld.dev/gh/jasnell/node-skills/node-sqlite
last_updated: 2026-11-19T20:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/binding-compat.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/binding-compat.mjs), [examples/diagnostics.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/diagnostics.mjs), [examples/new-names-vtab.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/new-names-vtab.mjs), [examples/portable-basics.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/portable-basics.mjs), [examples/security.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/security.mjs), [examples/serialize.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/serialize.mjs), [examples/statement-lifecycle.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/examples/statement-lifecycle.mjs), [meta.json](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/meta.json), [rules/advanced.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/advanced.md), [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/api.md), [rules/security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/security.md).
>
> If the user asked to install this Skill, run `npx skilld install jasnell/node-skills/node-sqlite`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/node-sqlite`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jasnell/node-skills/node-sqlite) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/node-sqlite`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/node-sqlite --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/node-sqlite --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# node:sqlite (current API)

| Feature | Versions | Stability | Flag |
| --- | --- | --- | --- |
| module, `DatabaseSync`/`StatementSync` | v22.5.0; unflagged v23.4.0, v22.13.0 | 1.2 RC (v25.7.0, v24.15.0) | none |
| `createTagStore`, `SQLTagStore` | v24.9.0 | 1.2 | none |
| `setAuthorizer` | v24.10.0 | 1.2 | none |
| `defensive`, `enableDefensive` | v25.1.0, v24.12.0; on by default v25.5.0, v24.14.0 | 1.2 | none |
| `database.limits` | v25.8.0, v24.15.0 | 1.2 | none |
| `serialize`, `deserialize` | v26.1.0, v24.16.0 | 1.2 | none |
| bind `boolean`, `ArrayBuffer` | v26.8.0, v24.21.0 | 1.2 | none |
| `statement.close`, `statement[Symbol.dispose]` | v26.8.0, v24.22.0 | 1.2 | none |
| `'sqlite.db.query'` channel | v26.8.0, v24.22.0 | 1 | none |
| `stat`, `resetStats`, `prepare({ persistent })` | v26.8.0 (not v24) | 1.2 | none |
| bind `undefined` as NULL | v26.10.0 (not v24) | 1.2 | none |
| `Database`/`Statement` names, `createModule` | v26.11.0 (not v24) | 1.2 | none |

> **Experimental API.** Before relying on these details, run the
> `node-experimental-check` skill's probe (or `node --version` plus a
> feature-detect one-liner) and check the docs for *the installed
> version*: `https://nodejs.org/docs/<version>/api/<module>.html`.
> If the installed version disagrees with this skill, the installed
> version wins.

## Portable import

```js
import * as sqlite from 'node:sqlite';
const Database = sqlite.Database ?? sqlite.DatabaseSync; // v24 has only DatabaseSync
```

On v24, `import { Database }` is a link-time SyntaxError.

## Tagged-template queries

```js
const db = new Database('app.db');
const sql = db.createTagStore(); // LRU cache of prepared statements (default 1000)
sql.run`INSERT INTO users(name) VALUES (${name})`; // ${} binds; it never interpolates
const user = sql.get`SELECT * FROM users WHERE id = ${id}`;
```

## Statements and disposal

```js
using db = new Database(':memory:');
{
  using stmt = db.prepare('INSERT INTO t VALUES (?, ?)'); // v24.22+/v26.8+
  stmt.run(1n, 'a');
} // finalized here
```

## Untrusted SQL

```js
const { constants: c } = sqlite;
const ok = new Set([c.SQLITE_SELECT, c.SQLITE_READ, c.SQLITE_FUNCTION]);
db.setAuthorizer((action) => (ok.has(action) ? c.SQLITE_OK : c.SQLITE_DENY));
db.limits.sqlLength = 10_000; // or new Database(p, { limits: { ... } })
```

## Pitfalls

- A JS number always binds as REAL. Use a bigint where INTEGER matters (TEXT or untyped columns, expressions, virtual tables).
- Before v24.21, a boolean throws and an `ArrayBuffer` silently binds NULL. Pass `BigInt(flag)` and `new Uint8Array(ab)` instead.
- Before v26.10, an anonymous `undefined` parameter throws. Use `null`.
- Never put `?` in tag-store SQL. v24.22+ and v26 throw `ERR_INVALID_ARG_VALUE`, while v24.19 silently binds NULL.
- Defensive mode blocks `writable_schema` edits. Use `{ defensive: false }` only for legacy tooling.
- The authorizer must not use its own connection. Since v24.22 that throws `ERR_INVALID_STATE`; older versions recurse.
- On v24, `prepare({ persistent })` is silently ignored. All calls are synchronous.

## Don't

- Don't add `better-sqlite3`/`sqlite3` when `node:sqlite` covers the need, and don't pass `--experimental-sqlite`.
- Don't build SQL with string concatenation or with an untagged template passed to `exec()`. Use the tag store or `?` parameters.
- Don't write `DatabaseSync` in code that only targets v26.11+.

## Reference

- [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/api.md): constructor options, every Database/Statement/SQLTagStore method, binding rules
- [rules/security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/security.md): authorizer action codes, defensive mode, limits, untrusted database files
- [rules/advanced.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-sqlite/rules/advanced.md): createModule, serialize, stat counters, diagnostics channel, sessions, backup
