Node.js has quietly shipped a built-in SQLite driver since v22.5.0, but it always carried a warning label: first experimental, then “release candidate”. That changed on 26 November 2026. In Node.js 27.0.0-alpha.0.2.0, the node:sqlite module is marked Stability: 2 – Stable (PR #67654). The same alpha adds a new statement.columnCount getter and graduates the handy --process-timeout flag to stable.
This tutorial shows how to use node:sqlite the modern way (including the renamed Database class), with an example we ran on the 27 alpha build, plus how --process-timeout can stop hung CI jobs.
What “stable” means here, and where you can use it
- 27.0.0-alpha.0.2.0 is an alpha release of the next major line. Use it for testing, not production.
- The stability label is new, but most of the API is not. It was a release candidate from v25.7.0 and v24.15.0 onward, and the docs record when each method arrived, so a lot of this code already runs on current LTS lines.
- The pull request notes that
node:sqlitelets applications work with SQLite databases without installing a native addon: nonode-gyp, no prebuilt binaries to break on a new Node version.
To try the alpha on Linux x64:
curl -LO https://nodejs.org/download/release/v27.0.0-alpha.0.2.0/node-v27.0.0-alpha.0.2.0-linux-x64.tar.xz
tar xf node-v27.0.0-alpha.0.2.0-linux-x64.tar.xz
./node-v27.0.0-alpha.0.2.0-linux-x64/bin/node --version
Heads-up: DatabaseSync is now Database
Since v26.11.0 the main class is called Database and the statement class Statement. The old names DatabaseSync and StatementSync remain as documentation-only deprecated aliases (DEP0210 and DEP0211). All the APIs are still synchronous. New code should use the new names:
// old (still works, deprecated in docs)
import { DatabaseSync } from 'node:sqlite';
// new
import { Database } from 'node:sqlite';
If you need to support older Node versions too, keep DatabaseSync for now. It is the same class.
A complete, working example
This small notes store covers the everyday operations: schema setup, prepared statements with named parameters, RETURNING, a transaction, the cached tagged-template API and an online backup. We ran it unchanged on v27.0.0-alpha.0.2.0.
// notes.mjs
import { Database, backup } from 'node:sqlite';
// `using` closes the connection automatically (Symbol.dispose)
using db = new Database('notes.db', { timeout: 2000 });
db.exec(`
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
body TEXT,
done INTEGER NOT NULL DEFAULT 0,
created TEXT NOT NULL DEFAULT (datetime('now'))
) STRICT;
`);
const insert = db.prepare(
'INSERT INTO notes (title, body) VALUES (:title, :body) RETURNING id'
);
const markDone = db.prepare('UPDATE notes SET done = 1 WHERE id = ?');
const open = db.prepare('SELECT id, title FROM notes WHERE done = 0 ORDER BY id');
// New in 27.0.0-alpha.0.2.0: does this statement return rows?
console.log('insert returns rows?', insert.columnCount > 0); // true (RETURNING)
console.log('update returns rows?', markDone.columnCount > 0); // false
const { id } = insert.get({ title: 'Try node:sqlite', body: 'It is stable now' });
insert.get({ title: 'Write the blog post', body: null });
console.log('changes:', markDone.run(id).changes); // 1
console.log(open.all());
// Tagged templates bind values safely and cache prepared statements (LRU)
const sql = db.createTagStore();
const q = 'blog';
console.log(sql.all`SELECT id, title FROM notes WHERE title LIKE ${'%' + q + '%'}`);
// A simple transaction
db.exec('BEGIN');
try {
for (const t of ['a', 'b', 'c']) insert.get({ title: t, body: '' });
db.exec('COMMIT');
} catch (err) {
db.exec('ROLLBACK');
throw err;
}
// Online backup to another file (returns a Promise)
await backup(db, 'notes-backup.db');
Output on the alpha:
insert returns rows? true
update returns rows? false
changes: 1
[ [Object: null prototype] { id: 2, title: 'Write the blog post' } ]
[ [Object: null prototype] { id: 2, title: 'Write the blog post' } ]
Things worth noticing
- Named parameters can be passed without the prefix (
{ title }for:title) becauseallowBareNamedParametersdefaults totrue. run()returns{ changes, lastInsertRowid }.get()returns the first row,all()returns every row, anditerate()streams rows.- Rows are null-prototype objects. That is deliberate, so a column called
constructorcannot clash withObject.prototype. Spread them ({ ...row }) if a library expects plain objects. - Foreign keys are on by default (
enableForeignKeyConstraints: true), and the defensive flag is on by default, which blocks SQL features that can deliberately corrupt the database file. timeoutsets SQLite’s busy timeout in milliseconds, which is useful when another process holds a lock.
Why columnCount is useful
statement.columnCount wraps SQLite’s sqlite3_column_count(). It is 0 for statements that return no data, such as INSERT, UPDATE or DELETE without RETURNING. That makes generic helpers (query runners, admin tools, migration scripts) much simpler:
function execute(db, text, params = {}) {
const stmt = db.prepare(text);
try {
return stmt.columnCount > 0
? { rows: stmt.all(params) }
: { ...stmt.run(params) };
} finally {
stmt.close();
}
}
execute(db, 'SELECT * FROM notes WHERE done = :done', { done: 0 }); // { rows: [...] }
execute(db, 'DELETE FROM notes WHERE done = 1'); // { changes, lastInsertRowid }
Before this getter, you had to call stmt.columns() and check the array length, or parse the SQL yourself.
Bonus: --process-timeout is stable too
Also in this alpha, --process-timeout=duration is no longer experimental (PR #67506). It exits the process with code 124 (the same code as the Unix timeout command) if it is still running after the given duration, and first prints what was keeping the event loop alive:
$ node --process-timeout=2s slow.mjs
(node:466298) Process timed out after 2s (--process-timeout). Exiting with code 124.
Main thread was not executing JavaScript.
Resources keeping the event loop alive:
Timeout (next due in 17ms)
That is ideal for CI test runs that sometimes hang because of a forgotten timer or open socket. A new --process-timeout-worker-stacks flag also prints what each Worker thread was doing. Note that 'beforeExit' and 'exit' events do not fire on timeout, but coverage and CPU profiles are still written.
{
"scripts": {
"test:ci": "node --process-timeout=10m --test"
}
}
Other changes in this alpha
util.TextDecoderandutil.TextEncoderare documentation-deprecated. Use the globalsTextDecoder/TextEncoder.- TLS renegotiation is documentation-deprecated, with a new
allowRenegotiationopt-in. - HTTP/2 compatibility API additions (
setHeaders,writeProcessing). - In builds without SQLite, loading
node:sqlitenow throws a clearERR_NO_SQLITEerror.
Takeaway
With node:sqlite officially stable, Node.js now has a supported, zero-dependency way to use SQLite for CLIs, desktop apps, tests, caches and small services. Start using the Database / Statement names, lean on prepared statements or the tag store for safe parameter binding, and add --process-timeout to CI so hung jobs fail fast with a useful report. Test on the 27 alpha now, so you are ready when the next major line is stable.
Sources: Node.js v27.0.0-alpha.0.2.0 release · node:sqlite documentation · PR #67654 – sqlite: mark as stable · PR #67658 – statement.columnCount · CLI docs: –process-timeout
