r/node • u/Nefzaoui • 5d ago
Using Node 24's built-in node:sqlite in a real app for four months: what worked, and a few gotchas
I've been running a self-hosted Minecraft server panel on Node since July (MIT, https://github.com/anefzaoui/minecraft-server-manager), and one decision I'd like other opinions on is that it uses Node's built-in node:sqlite instead of better-sqlite3 or an ORM. Disclosure: it's my own project, and I built it with Claude Code. I designed it, decided every feature, review the changes and test every release on our own servers, and Claude wrote most of the code.
What worked:
- No native module. The app ships as an amd64 + arm64 Docker image, and not compiling a SQLite binding for each arch removed a whole class of install problems
- Synchronous is fine here. It's a single-process panel with a small database. WAL mode plus synchronous calls kept the code simple, and the slow work (Docker calls, zipping backups) is async or in a worker thread anyway
- One module owns the driver. Everything goes through a tiny API (
run / get / all / exec / transaction(fn) / backupTo), with a prepared-statement cache keyed on the SQL text, so the rest of the code never sees the driver - Migrations as numbered files applied on boot. Boring and that's the point
The gotchas:
- it needs Node 24+ to be flagless, so the
enginesfield and the README say so loudly - for backups,
backupTogives you a consistent copy of the live database; copying the .db file next to a live WAL does not - a backup of the whole app is the one data folder, which only works because a path guard rejects any file path that escapes it (symlinks included)
Has anyone else moved a production-ish app to node:sqlite yet? Curious whether you hit anything I haven't.
13
u/insomniac2846 5d ago
I’ve been using the native SQLite module in a project I’m working on and combined it with workers to move the queries off of the main thread. Happy to share an example
10
u/SpartanDavie 5d ago
Crazy seeing this.First, with their being so many AI replies on Reddit these days I just want to clarify I'm not a bot and don't know OP, as I think what I will say may make it sound staged.
Anyway, my son quite like Minecraft and wants a little server. And I only know Node for backend dev and presumed I'd probably have to know Java. I've been learning some Rust and on a whim decided to search if I can set up a server for him in Rust and came across this!
I haven't set it up yet, so I hope you don't mind me picking your brains with a few questions?
As a side note, if you are using Tailscale, Tailscale the just released Tailcat and they did a Minecraft demo on YouTube
5
u/uwemaurer 4d ago
I use node:sqlite too and it works quite well for us. We used better-sqlite3 before which is great too but not needed anymore since it is available via node. We use https://github.com/sqg-dev/sqg/ to produce the SQL client code and handle migrations
1
u/nadmaximus 4d ago
I used it in testing, but ultimately a custom document-based database was better for my purpose.
1
u/pRayrtuck 3d ago
skipping the native binary build step across architectures is honestly the biggest win here. did you run into any memory growth with the prepared statement cache, or do you cap the number of keys?
1
u/Solonotix 5d ago
Edit: LOL, I was reading the other comment and was wondering why they mentioned Minecraft. I then went back up and realized I totally skipped OP mentioning their Minecraft server repo. Ah, well, my comment still stands, but I need to not skim the details
With a language runtime like Node.js, which was originally designed for event-driven architecture in web hosting, how does SQLite fit into a micro-service world? Not trying to be snide about it, because I love the concept for any locally-hosted or native application. I'm just legitimately curious about how you would use it, say, in a containerized deployment. Does SQLite provide any replication capabilities for synchronizing across multiple nodes?
But maybe I'm just asking the wrong question. Maybe this is intended for all of the Electron apps, or React-Native, etc., in which you aren't operating a distributed system.
2
u/codeedog 5d ago
Thanks for this. I have an app I built a few years ago that retains some state and rather than plug in a database, I’ve been using a file, but it’s always bugged me. With a native db library, I think I’ll just switch to SQLite, much cleaner. I don’t need anything fancy, but this would address quite a few problems I could solve much more cleanly with tables.