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 } Meer dan eenvoudige velden
De snelstart zet alleen velden op het hoogste niveau. Een MindooDB-document is een Automerge-CRDT, en elk veld heeft een type dat bepaalt hoe gelijktijdige wijzigingen worden samengevoegd: collaboratieve tekst, rich text, atomaire strings, tellers, tijdstempels, lijsten en maps. Binnen changeDoc() kun je ook geneste velden en lijsten bewerken (push, splice), en getFieldType() vertelt je hoe een veld is opgeslagen.
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" Documenten lezen en schrijven: alle veldtypen met voorbeelden →
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.