Node.js quickstart
By the end of this page you will have a running Node.js script that creates an end-to-end encrypted document store, writes a todo, and reads it back — all in under 5 minutes.
1) Install
Create a new project (or use an existing one) and install MindooDB. Node.js 20+ is required.
npm init -y
npm install mindoodb 2) Create index.mjs
Paste the following into index.mjs. The createTenant call generates all cryptographic keys (admin signing key, user signing key, encryption keys, tenant key) and registers the first user in a single step. After that, we open a database and create a document — every change is automatically signed and encrypted.
import {
BaseMindooTenantFactory,
InMemoryContentAddressedStoreFactory,
} from "mindoodb";
async function main() {
const storeFactory = new InMemoryContentAddressedStoreFactory();
const factory = new BaseMindooTenantFactory(storeFactory);
// One call creates admin + user keys, KeyBag, and directory
const { tenant, adminUser, appUser, keyBag } =
await factory.createTenant({
tenantId: "my-first-tenant",
adminName: "cn=admin/o=demo",
adminPassword: "admin-password",
userName: "cn=alice/o=demo",
userPassword: "user-password",
});
// Open a database and create a todo document
const db = await tenant.openDB("todos");
const todo = await db.createDocument();
await db.changeDoc(todo, async (d) => {
const data = d.getData();
data.title = "Buy milk";
data.done = false;
});
// Read it back
const ids = await db.getAllDocumentIds();
const loaded = await db.getDocument(ids[0]);
console.log("Loaded todo:", loaded.getData());
}
main(); 3) Run
node index.mjs Expected output:
Loaded todo: { title: 'Buy milk', done: false } Oltre i campi semplici
La guida rapida imposta solo campi di primo livello. Un documento MindooDB è un CRDT Automerge e ogni campo ha un tipo che stabilisce come vengono unite le modifiche simultanee: testo collaborativo, rich text, stringhe atomiche, contatori, timestamp, liste e mappe. Dentro changeDoc() puoi modificare anche campi annidati e liste (push, splice), e getFieldType() ti dice come è memorizzato un campo.
import { MindooValue } from "mindoodb";
await db.changeDoc(todo, (d) => {
const data = d.getData();
data.status = MindooValue.atomic("open"); // replaced as a whole
data.votes = MindooValue.counter(0); // concurrent +1s add up
data.tags = ["home"];
data.tags.push("urgent"); // list insert, merges
d.updateText("title", "Buy oat milk"); // only the changed characters
});
const doc = await db.getDocument(todo.getId());
doc.getFieldType("status"); // "atomic" Leggere e scrivere documenti: tutti i tipi di campo con esempi →
What's next?
You have a single-user setup. The real power of MindooDB is multi-user collaboration with end-to-end encryption — where the server never sees plaintext.