Nazbu is a local-first sync engine. Point it at the data your app already uses, and your app keeps working on every device — with or without internet, and with no server.
Most apps treat the internet as a lifeline: the connection drops and everything freezes. Nazbu flips that. Every device holds its own full copy of the data, talks to the other devices directly, and everyone converges automatically the moment they can reach each other again — on the same network or across the internet.
What you get
Offline by default — the app runs entirely on the device, no round-trip required.
No server — devices sync peer-to-peer. A cloud node, if you want one, is just another peer.
Across networks — peers on different networks connect straight through, not just over the same Wi-Fi.
Durable & ordered — every change is stored locally and replays in order when a peer reconnects.
Isolated — a room keeps each app, site or tenant’s data cleanly apart.
Where it fits. If your app has a real database and real users on shaky or no connectivity — a shop, a warehouse, a clinic, a field team — Nazbu keeps it running without a rewrite.
Getting started
Installation
Nazbu runs on Node.js 18 or newer. Add it to the project you already have — nothing else to run, no broker, no daemon, no account.
terminal
npm i nazbu
If you sync a database, add its driver too — pg for PostgreSQL or mongodb for MongoDB:
terminal
npm i nazbu pg # for PostgreSQL
npm i nazbu mysql2 # for MySQL / MariaDB
npm i nazbu better-sqlite3 # for SQLite
npm i nazbu mongodb # for MongoDB
TypeScript works out of the box. Type definitions ship inside the package — no @types/nazbu to install. You get full autocomplete and type-checking for the API, the options, and the events.
Getting started
Quick start
A name, a room, and you’re syncing. Run this on two machines with the same room and they find each other and share history automatically.
const Nazbu = require('nazbu')
const room = newNazbu({ name: 'till-1', room: 'shop-42' })
// fires for every message — from other devices AND your own
room.on('message', (data, meta) => console.log(meta.from, data))
room.on('peers', (n) => console.log('peers:', n))
await room.start()
room.send({ type: 'sale', total: 4500 })
name is this device’s friendly label; room is the group it syncs with.
start() begins discovery and replicates any history that already exists.
send() appends a message to this device’s log and broadcasts it — even offline, it ships the moment a peer appears.
Because message also fires for your own sends, a brand-new device replays the full history when it joins.
Try it. Copy the file to a second machine, keep the same room, change the name, and run both. Send from one — it shows up on the other. Pull the network cable, keep sending, plug it back in: they reconcile on their own.
Core concepts
How sync works
Every device keeps a durable, append-only log of its own changes. Peers replicate each other’s logs, so everyone ends up with the same history — in the same order.
Append, don’t overwrite
When you call send(), Nazbu appends the message to this device’s log. Logs are never edited in place, only extended. That’s what makes reconnection safe: a peer that was away simply receives the entries it missed and appends them.
Replay is history
The message event fires for every entry, including your own and everything that predates a new peer joining. A device that comes online for the first time replays the whole story and arrives at the exact same state as everyone else.
Durable and offline-safe
Because each log lives on disk locally, an app keeps working with no peers at all. Changes queue up and flow out the instant another device is reachable — same room, same network or a different one.
Event-sourced by nature. Sync at this layer is a union of append-only logs, so there are no lost writes to reconcile. Higher-level rules (see Conflict handling) decide how those events fold into your database.
Core concepts
Rooms & isolation
A room is the boundary of sync. Only devices in the same room discover and replicate with each other — everything else is invisible.
rooms.js
newNazbu({ name: 'till-1', room: 'shop-42' }) // only talks to shop-42newNazbu({ name: 'till-9', room: 'shop-77' }) // never sees shop-42
Two shops on the same Wi-Fi, two apps on the same machine, two tenants in the same product — different rooms means zero cross-talk. If you omit room, everyone lands in default.
Rooms are how you go multi-tenant
Give each tenant its own room — for example room: 'tenant-' + tenantId — and a device only ever syncs its own tenant’s data. See the multi-tenant guide.
Core concepts
Peers & networking
Nazbu finds peers on the local network out of the box, and can reach peers across the internet — on completely different networks — when you ask it to.
Local network
By default, devices discover each other on the LAN with no configuration. Put them on the same access point and they connect — no router setup, no static IPs.
Across networks
Turn on internet transport and peers on different networks connect directly through the internet, punching through typical home and office routers, with a relay as a fallback for the strictest ones. No shared Wi-Fi and no VPN required.
internet.js
newNazbu({ name: 'shop-hub', room: 'shop-42', internet: true })
// now syncs on the LAN *and* to peers anywhere on the internet
Discovered vs connected
Two signals tell you what’s really happening:
peers — devices Nazbu has discovered.
links — devices it is actually connected to and replicating with.
If peers is up but links is 0, the devices can see each other but the connection is blocked — usually a firewall or client-isolation setting on the access point. Fix that and the link comes up on its own.
Core concepts
Conflict handling
Two devices edit while apart, then reconnect. Nazbu folds their changes together with rules you can reason about — so nothing is silently lost or double-counted.
Two kinds of data
Records that change in place (a product, a customer, settings) merge last-writer-wins: the most recent edit stands, decided by a per-change version stamp.
Things that accumulate (stock movements, sales, ledger entries) are treated as append-only: every entry is kept and unioned, so two tills selling offline both count. Totals are derived from those entries, never overwritten.
Why it matters for money. Append-only means concurrent sales from two offline devices don’t clobber each other — the ledger keeps both, and the balance is the sum. That’s the difference between “roughly synced” and “books that reconcile”.
Database adapters apply these rules automatically per collection or table; you choose which fields are records and which are accumulators.
Core concepts
Files & data
Records aren’t the whole story — receipts, photos, signatures and attachments have to travel too. Nazbu syncs binary files alongside the records that point at them.
Files are split into chunks and replicated like any other change, so a photo taken on an offline device shows up intact on every other device once they reconnect. A record and its file arrive coherently — you never end up with a row pointing at a picture that isn’t there.
Large and transient files. Adapters can skip things that shouldn’t travel — huge backups, temporary exports — so sync stays lean and only carries what your app actually references.
Databases
PostgreSQL
Sync a live PostgreSQL database with zero changes to your app. A tiny trigger on each table records changes; Nazbu replicates them and applies them back on every peer.
Requirements
PostgreSQL 13+ and a single-column primary key on each synced table.
Under the hood it uses triggers plus LISTEN/NOTIFY. Your tables are never altered — Nazbu keeps its own bookkeeping in a few helper tables.
Databases
MySQL / MariaDB
Sync a live MySQL or MariaDB database with zero changes to your app. Triggers record each change into an outbox; Nazbu replicates and applies it on every peer.
Requirements
MySQL 5.7+ / 8.0+ / 9.x or MariaDB 10.2+, and a single-column primary key on each synced table.
MySQL has no notifications, so the adapter polls a small outbox table. Your tables are never altered.
Databases
SQLite
Sync a local SQLite database with no server at all — just a file. Ideal for edge devices, kiosks and mobile. Triggers capture changes; Nazbu replicates and applies them on every peer.
Requirements
A single-column primary key on each synced table.
The better-sqlite3 driver: npm i nazbu better-sqlite3.
The database is a single file, so this is the simplest offline-first setup there is — two devices, two files, always in sync.
Databases
MongoDB
The MongoDB adapter syncs a live database with zero changes to your app. It watches Mongo’s change stream, replicates over Nazbu, and applies incoming changes back into each peer’s database.
Requirements
MongoDB running as a replica set (single-node is fine) — that’s what enables change streams.
Connect with directConnection=true so the change stream attaches to that node.
Sync the whole database slice this node owns (all its collections), not just one.
--room
The sync group. Use one room per tenant/site to keep data apart.
--name
Friendly name for this node in logs and presence.
--uri
Your existing Mongo connection string.
--db
Database to mirror.
--internet
Also sync across networks, not just the LAN.
Your application keeps reading and writing Mongo exactly as before. The adapter never touches your documents’ shape — its own bookkeeping lives in a separate place.
Databases
Your database
Point Nazbu at the database handle you already have — one line — and it wires the matching adapter and keeps that database synced across every peer.
one-line.js
const room = newNazbu({
db: pool, // a pg Pool, mysql2 Pool, better-sqlite3 DB, or mongodb Db
room: 'hospital-42',
internet: true,
policies: { sales: 'append-only', '*': 'last-writer-wins' }
})
await room.start() // that database is now offline-first, on every node
Under the hood: a thin contract
An adapter is just a source that emits changes and a sink that applies incoming ones. Anything that can report its changes can plug in.
adapter (shape)
// a change SOURCE — tell Nazbu what changed
onChange((change) => nazbu.send(change))
// an apply SINK — write what arrives from peers
nazbu.on('message', (change) => applyToDb(change))
Because most databases expose a change feed — a replication log, a write-ahead log, triggers — the same pattern covers a wide range of systems.
Database
Change source
Status
PostgreSQL
triggers + LISTEN/NOTIFY
available
MySQL / MariaDB
triggers + outbox polling
available
SQLite
triggers + outbox polling
available
MongoDB
change streams
available
Want an adapter for a database that isn’t listed? The contract above is all it takes — open an issue and let’s scope it.
Guides
Multi-tenant apps
One product, many customers, one database — and no customer should ever see another’s data. With Nazbu, tenancy is a room.
Run one sync node per tenant and scope it to that tenant’s room. A device only discovers and replicates its own tenant, even if a dozen tenants sit on the same network.
With a database adapter, point it at the same room and it filters that tenant’s records — so a shop only ever syncs its own slice, and a shared cloud node can serve every tenant, each on its own room.
Proven at scale of a business. This is exactly how Womola runs: many shops, each a room, all isolated, all syncing to one cloud.
Guides
Offline-first shops
The classic setup: a site that must keep selling when the internet is down, and catch up with head office when it’s back.
The topology
One hub per site runs your app, its database, and a Nazbu node.
Tills and devices on the site talk to the hub over the local network.
A cloud node joins each site’s room with internet: true and receives everything the moment a connection exists.
Sales, stock and files all accumulate locally with no internet. When the link returns, the site and the cloud reconcile automatically — the cloud is just another peer, never a dependency for the shop to function.
Nazbu syncs, the Hub runs. Nazbu handles the data. Making the app itself run on-site — backend, database, a local address, background service and auto-update — is the job of its companion, Nazbu Hub. Together they make any app offline-first from one config file.
Result. The shop never stops. Head office sees everything, live, as soon as there’s a connection — and if there isn’t, nothing is lost.
API reference
new Nazbu(options)
Create a node. It joins a room and, once started, discovers peers and syncs.
Option
Type
Description
name
string
Friendly device name. Defaults to a per-process id.
room
string
Isolation boundary — only same-room nodes sync. Defaults to 'default'.
internet
boolean
Add internet transport to reach peers across networks. LAN is always on.
storage
string
Where this node keeps its local data. Defaults to a folder per room and name.