Get Started / Node.js

Node.js quickstart

Fastest path to a running encrypted todo example in Node.js.

1) Install

npm init -y
npm install mindoodb

Use Node.js 20+.

2) Create index.mjs

import {
  BaseMindooTenantFactory,
  InMemoryContentAddressedStoreFactory,
  KeyBag,
} from "mindoodb";

async function main() {
  const storeFactory = new InMemoryContentAddressedStoreFactory();
  const factory = new BaseMindooTenantFactory(storeFactory);

  const user = await factory.createUserId("CN=node-todo-user/O=demo", "user-password");
  const keyBag = new KeyBag(user.userEncryptionKeyPair.privateKey, "user-password");
  const adminSigning = await factory.createSigningKeyPair("admin-password");
  const adminEncryption = await factory.createEncryptionKeyPair("admin-password");

  const tenant = await factory.createTenant(
    "node-todo-tenant",
    adminSigning.publicKey,
    adminEncryption.publicKey,
    "tenant-password",
    user,
    "user-password",
    keyBag
  );

  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;
  });

  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 includes: Loaded todo: { title: 'Buy milk', done: false }