@livestore/adapter-node runs LiveStore in Node.js with SQLite-backed persistence on the filesystem. It exposes two adapters:
makeAdapter— single-threaded; leader logic runs in the same thread as your applicationmakeWorkerAdapter— multi-threaded; leader logic (persistence, sync, SQLite) runs in a separate worker thread
Installation
- npm
- pnpm
- yarn
Exports
makeAdapter
Creates a single-threaded Node.js adapter. The leader thread (persistence and sync) runs in the same thread as your application. Use this for CLI tools, scripts, and simple applications where simplicity matters more than throughput.Parameters
Filesystem storage configuration:Data is stored at
{baseDirectory}/{storeId}/.Optional sync backend for multi-device synchronization.
Stable identifier for this Node.js process. Defaults to the machine hostname.
Session identifier. The adapter does not currently support multiple concurrent sessions per client.
Deletes all persisted data for this store on startup. Use only during development.
Enable the LiveStore DevTools server.
Example
makeWorkerAdapter
Creates a multi-threaded Node.js adapter. The leader thread runs in a separateworker_threads worker, keeping your main thread responsive.
Use this for production servers and performance-critical applications.
Parameters
URL of the worker file. Use
import.meta.url to make it relative to the current file:Same as
makeAdapter.Extra arguments passed to the worker, accessible in the worker via
getWorkerArgs().NodeAdapterOptions also apply.
Worker file setup
Create a worker file that callsmakeWorker:
livestore.worker.ts
Full example
app.ts
Worker exports
@livestore/adapter-node/worker exports:
makeWorker
Bootstraps the leader worker thread. Call once in your worker file.
The schema to use in the leader thread.
Optional sync backend.
getWorkerArgs
Reads the arguments passed from the main thread via workerExtraArgs:
Peer dependencies
| Package | Version |
|---|---|
effect | ^3.19.19 |