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 } Mer enn enkle felt
Hurtigstarten setter bare felt på øverste nivå. Et MindooDB-dokument er en Automerge-CRDT, og hvert felt har en type som bestemmer hvordan samtidige endringer slås sammen: samarbeidstekst, rik tekst, atomiske strenger, tellere, tidsstempler, lister og maps. Inne i changeDoc() kan du også redigere nestede felt og lister (push, splice), og getFieldType() forteller hvordan et felt er lagret.
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" 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.