The muscle-memory move when a Node project needs a SQL database is an npm package. Meanwhile the runtime has carried one since v22.5.0.
node:sqlite is a synchronous SQLite binding inside Node itself. No npm install, no native addon compiled for your platform, no flag since 22.13. It arrived quietly, and it's easy to miss in a changelog full of bigger headlines. I wanted to know whether it's good enough for something a React developer actually does: render a component from data, and test that component without mocking the data away.
So I built exactly that. A small task list component, a data layer on node:sqlite, and a script that asserts what happens on Node 22.23.3, 24.21.0 and 26.10.0. The whole harness is in the repo, and npm test there backs every result below. One honest limit up front: the component is rendered on the server with renderToStaticMarkup from React 19.3.1. I haven't run it inside Next.js, Astro or any framework, and I haven't measured it against better-sqlite3.
Is node:sqlite Stable Enough to Use?
Not yet, according to the docs, and the versions disagree about how not-yet.
The module was added in v22.5.0 behind --experimental-sqlite. The docs history says that flag went away in v22.13.0 and v23.4.0, "but still experimental." The v22 page labels it Stability 1.1, active development. The v24 page says 1.2, release candidate, from v24.15.0. The v26 page also says 1.2 and dates its release-candidate step to v25.7.0.
What did I see? Node 22.23.3 printed ExperimentalWarning: SQLite is an experimental feature and might change at any time on first use. Node 24.21.0 and 26.10.0 printed nothing. The old flag still works as a no-op on all three. On Node 20.19.5 I tried the import by hand and got ERR_UNKNOWN_BUILTIN_MODULE: No such built-in module: node:sqlite, so there's no polyfill story to worry about, just an engines field to set. If you're on 20, the Node 20 to 24 migration guide is the first job.
Two smaller facts. The module only exists under the node: scheme, and a bare import 'sqlite' fails with ERR_MODULE_NOT_FOUND in my run. And each Node version bundles its own SQLite: 3.51.3 in 22.23.3, 3.53.4 in 24.21.0 and 26.10.0, read from process.versions.sqlite. Your SQL will behave the same, your edge cases around newer SQLite features might not.
What Does a Component Test on a Real Database Look Like?
Short. The data layer is a handful of functions over a DatabaseSync:
import { DatabaseSync } from 'node:sqlite';
export function openTaskDb(location = ':memory:') {
const db = new DatabaseSync(location);
db.exec(`
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL UNIQUE,
points INTEGER NOT NULL CHECK (points BETWEEN 1 AND 13),
done INTEGER NOT NULL DEFAULT 0 CHECK (done IN (0, 1))
) STRICT;
`);
return db;
}
export const listTasks = (db) =>
db.prepare('SELECT id, title, points, done FROM tasks ORDER BY id').all();
And the test creates a new database for every case:
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createElement as h } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { addTask, listTasks, openTaskDb } from './db.mjs';
import { TaskList } from './TaskList.mjs';
let db;
beforeEach(() => { db = openTaskDb(); });
test('a title from the database is escaped, not trusted', () => {
addTask(db, '<img src=x onerror=alert(1)>', 2);
const html = renderToStaticMarkup(h(TaskList, { tasks: listTasks(db) }));
assert.ok(html.includes('<img src=x onerror=alert(1)>'));
});
That's the whole trick. Per the SQLite docs, every connection that opens :memory: gets its own private database, which disappears when the connection closes. There's no cleanup step and no shared state leaking between tests, and the constraints in the schema (UNIQUE, CHECK, STRICT) are the real ones, not a mock's guess at them. The five tests in the example run under node --test with zero test dependencies beyond React itself. If you want the runner trade-offs, the comparison with Jest covers them.
How much does a fresh database cost? I timed open, create table, insert 20 rows in one transaction and close, 300 times per round, five rounds. Median: 15 ms per round on every version. That's 0.05 ms per database.
Opening, migrating and seeding a private database took 0.05 ms in my runs, so a mock now has to be cheaper than that to be worth writing.
Is that a fair benchmark? It's a tiny schema on an Apple silicon Mac, so treat it as an order of magnitude, not a promise. A schema with forty tables and a few thousand seed rows will cost more, and you'd copy a prepared template rather than rebuild it.
How Do Transactions Work Without a Helper?
You write them yourself. There's no db.transaction(fn) in node:sqlite; the module gives you exec('BEGIN'), exec('COMMIT') and exec('ROLLBACK'), plus a read-only isTransaction property (v22.16.0 and v24.0.0 according to the docs). Mine is nine lines:
export function inTransaction(db, fn) {
db.exec('BEGIN');
try {
const result = fn();
db.exec('COMMIT');
return result;
} catch (error) {
if (db.isTransaction) {
db.exec('ROLLBACK');
}
throw error;
}
}
The isTransaction guard earns its place. SQLite rolls some failures back on its own, and a second ROLLBACK then throws, which hides the real error behind a confusing one.
Here's what I confirmed by running it. A batch of three inserts committed as one unit. A batch whose second row broke the UNIQUE constraint left the table at its previous three rows and isTransaction back at false. A failing statement inside BEGIN did not end the transaction by itself (isTransaction stayed true), so you must roll back on purpose. And nesting inTransaction inside itself throws cannot start a transaction within a transaction, since SQLite has no nested transactions without savepoints, which I didn't test.
Which Type Surprises Hit a React Developer?
Three, and they're all about the data crossing into your components.
Rows have a null prototype. db.prepare('SELECT 1 AS a').get() prints [Object: null prototype] { a: 1 }. React doesn't care, and neither does JSON.stringify. But assert.deepStrictEqual(row, { id: 1, ... }) fails on the prototype alone. Spread the row first, { ...row }, and it passes. If your test library compares prototypes, expect the same thing there; I only verified it with node:assert.
Big integers throw. I stored 9007199254740993 (2^53 + 1) in an INTEGER column. Reading it back threw ERR_OUT_OF_RANGE: Value is too large to be represented as a JavaScript number. That's a good default, because silent rounding would be worse. The fix is statement.setReadBigInts(true), which returns the exact BigInt. The catch for UI work: JSON.stringify throws a TypeError on a BigInt, so convert before the value reaches a prop or a serialized payload.
Binding rules changed across versions. Dates and plain objects can't be bound on any version (ERR_INVALID_ARG_TYPE), so store ISO strings or epoch numbers. Booleans are where it gets odd. Node 22.23.3 rejected true. Node 24.21.0 and 26.10.0 accepted it. The v26 page dates boolean binding to v26.8.0, so I expected 24.21.0 to reject it too. It didn't, and I didn't dig through the changelog to find out whether it was backported. undefined is stricter: it threw on 22 and 24 and bound as NULL on 26.10.0, which matches the v26 docs entry for v26.10.0.
What Happens When a Query Blocks?
Everything blocks. DatabaseSync and StatementSync are synchronous by design, and the only promise in the module is sqlite.backup().
I made that concrete. I scheduled a setTimeout with a 0 ms delay, then ran a recursive query that generates three million rows and counts them. The timer could not fire until the query returned, and the query held the thread for about 350 ms (347 to 363 ms across the three versions). Then I awaited a short timeout and the callback fired.
Is 350 ms a problem? For a three-million-row scan, probably not; you'd never ship that query. For a server that handles other requests on the same thread, a 40 ms query is already 40 ms of nobody else being served. It's the same mechanism the event loop guide walks through, only with a database holding the thread instead of a loop.
My opinion, and you may disagree: this makes node:sqlite a better fit for tests, build tooling and small single-user servers than for a busy API. A synchronous driver that is fast per call is fine until the day one query isn't.
What Differs Between Node 22, 24 and 26?
The SQL is identical. The edges aren't.
Beyond the table, the docs list a few things worth knowing before you pin a version. sqlite.backup() and database.location() exist on 22.16.0 and later. isOpen and Symbol.dispose exist from 22.15.0. database.serialize() and deserialize() arrive in v26.1.0, and createModule() for virtual tables in v26.11.0. I used none of those in the example, so that's the docs talking, not my runs.
The change that will touch your imports is a rename. The v26 deprecations page lists DEP0210 and DEP0211, documentation-only entries from v26.11.0: DatabaseSync becomes Database and StatementSync becomes Statement, with the old names kept as deprecated aliases. On 26.10.0 the module still exports only DatabaseSync, StatementSync, Session, constants and backup, so I couldn't run the new names. Nothing breaks today. When you write new code, I'd isolate the constructor in one file, which is what openTaskDb does, so the rename is a one-line change.
When Is It the Wrong Tool?
When you need what it doesn't have, and the list is long enough to matter.
- No connection pool and no async API, so a busy request path is the wrong place for it.
- No ORM, no migrations, no query builder. You're writing SQL strings, though
STRICTtables andCHECKconstraints catch a lot. - Extension loading is off unless you pass
allowExtension: true, per the docs. - A stability label that still isn't plain Stable.
- Client-side behavior: a component test here doesn't tell you what the browser does with focus, layout or events. For that you still need jsdom or a real browser, as the React component testing guide explains.
I haven't tested WAL mode, sessions, changesets, worker-thread access to one file, Windows or Linux. The example ran on macOS arm64 only.
Would I use it today? For tests and local tooling, yes, without hesitation. For a production service, I'd wait for the label to change and for the Database rename to settle, then rerun the harness on whatever Node I ship.
Run It Yourself
cd blogs/coding-dunia/examples/node-sqlite-in-memory
npm install # react and react-dom only
npm test # needs Node 22.13 or newer
The script prints each result and fails if any answer changes. Run it under the Node you deploy. Version gates decide which assertions apply, so a result that differs from this page is information, not a flake.
If You're Also Dealing With...
- Which Node to run: the Node 24.19.0 LTS notes and the Node 24 features guide.
- Running TypeScript with no loader: native TypeScript in Node.
- Limiting what a script can reach: the permission model, tested.