r/node • • 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 engines field and the README say so loudly
  • for backups, backupTo gives 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.

48 Upvotes

26 comments sorted by

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

3

u/Nefzaoui 5d ago

oh nice, yes please, i'd love to see it! in my case the database is small and single-process, so plain synchronous calls on the main thread have been fine so far, and the slow stuff (Docker calls, zipping backups) already lives elsewhere. curious how you hand results back from the worker: a message per query, or batches? and do you open one connection per worker, with WAL?

1

u/insomniac2846 5d ago

Here you go https://codeberg.org/buildkitchen/sql_driver . Still working something’s out before I make it a real npm package

1

u/Nefzaoui 4d ago

thanks for sharing! will have a look at how you split the queries across the workers, good luck with the npm release 🙂

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?

  1. I have a spare RPi 5, 16gb. Can I use that?
  2. If so, should I use Ubuntu Desktop or server?
  3. Can I set up Cobblemon on it? That's what he and his friend want to try (they currently just play the normal one).
  4. I usually set up something like Tailscale or similar if I have a local thing open to the net. Do I need to do anything special?

As a side note, if you are using Tailscale, Tailscale the just released Tailcat and they did a Minecraft demo on YouTube

3

u/Nefzaoui 5d ago

ha, not staged, I promise, and of course, ask away 🙂

  1. a Pi 5 with 16 GB should be fine. the image is built for arm64 too, so it runs there, though I'll be honest that I haven't run it on a Pi 5 myself yet. if you hit anything, open an issue and I'll help
  2. server, not desktop. Ubuntu Server 64-bit or Raspberry Pi OS Lite 64-bit, then Docker. no desktop means more RAM left for Minecraft
  3. yes, Cobblemon works. in the create wizard you pick the Cobblemon modpack from Modrinth and it pins that exact version. give it 4–6 GB of RAM, and the kids need the same modpack version on their side (the Modrinth app or Prism makes that easy)
  4. Tailscale is perfect here. keep the panel itself only reachable on your tailnet, because it talks to Docker, which is basically root on the Pi. for his friend, either share the Pi on your tailnet or forward only the Minecraft port (25565), never the panel's

have fun with it, and tell me how it goes!

1

u/NeverendingBacklog 5d ago

not op but i set up a minecraft server on a pi4 - i think the biggest gotcha is you need a 64bit version of java on the pi. i have mine on an arch linux distro... its not the best experience tbh. the server is just for me and my son and any large farms causes massive server lag. just as an fyi. its great to bang around on but dont expect to build legendary automated farms on it.

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/Nefzaoui 4d ago

oh nice, hadn't seen sqg, generating the client code from the SQL is a neat idea. no native module to build was the whole reason i went with node:sqlite from the start, it keeps installs (and arm64) simple. thanks for the link!

1

u/nadmaximus 4d ago

I used it in testing, but ultimately a custom document-based database was better for my purpose.

3

u/Nefzaoui 4d ago

fair, it's not the right fit for everything! mine is tiny and very relational (servers, schedules, backups, users), so plain tables suit it. what made a document store the better fit for yours?

1

u/nadmaximus 4d ago

basically, I needed persistence, and to easily use separate VPS for serving segregated zones of data (it's a game with multiplayer instances). Writes are relatively infrequent. With document-based database, nfsv4 over a secure network gives me 'easy' scaling by segmentation.

2

u/Nefzaoui 3d ago

ah that makes sense, and sqlite on nfs is asking for locking trouble anyway, so splitting by zone with documents sounds like the right call. cool setup, good luck with the game!

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/Nefzaoui 3d ago

yeah that was the main reason for me too! no cap right now, it's a plain Map keyed on the SQL text. most queries are fixed strings so those can't grow, but your question made me check the rest, and the ones that build an IN (?,?,...) list add a new entry for every list length, so a few hundred per query in the worst case, and it never shrinks. opened an issue for it, probably passing the list as one json param so the SQL stays the same https://github.com/anefzaoui/minecraft-server-manager/issues/111 thanks!

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.

5

u/Nefzaoui 5d ago

not snide at all, it's the right question. for a micro-service setup I wouldn't use it: SQLite has no replication of its own, so anything shared across nodes wants Postgres or similar (or something like LiteFS if you really want SQLite everywhere). this panel is the other kind of app, one process on one box managing that box's containers, so a single local file with WAL is exactly enough, and the whole app's state is one folder you can back up or move

5

u/codeedog 5d ago

One node server can handle a large number of web clients on its own. For a lightly loaded site, it’s perfectly fine, especially if using asynchronous calls (OP said they used synchronous). Plus, it’s not that complicated to switch to an event queue or a database capable of sharing across multiple processes, if necessary.

Not everyone builds a public web application with DAUs measured in the millions.

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.