Skip to content
Nuvyntra Labs

Platform integration

Node.js

@nuventra/nuvexadb-node (koffi). NUVEXA_NATIVE_LIB is required.

Overview

@nuventra/nuvexadb-node loads the C ABI with koffi. NUVEXA_NATIVE_LIB is required.

1. Download

From NuvexaDB v1.0.6:

Your machineNode zipNative zipLibrary file
macOS Apple SiliconNuvexaDB-Node-osx-arm64.zipNuvexaDB-Native-osx-arm64.ziplibnuvexa.dylib
Linux x64NuvexaDB-Node-linux-x64.zipNuvexaDB-Native-linux-x64.ziplibnuvexa.so
Windows x64NuvexaDB-Node-win-x64.zipNuvexaDB-Native-win-x64.zipnuvexa.dll

Inside the Node zip: nuventra-nuvexadb-node-1.0.6.tgz (npm pack of @nuventra/nuvexadb-node).

This is the desktop Node SDK. For React Native apps see react-native.md.

2. Empty project

mkdir acme-store && cd acme-store
npm init -y

Use "type": "module" in package.json (the SDK is ESM).

3. Add the downloaded package

npm install /path/to/nuventra-nuvexadb-node-1.0.6.tgz
export NUVEXA_NATIVE_LIB="/absolute/path/to/libnuvexa.dylib"

Windows:

$env:NUVEXA_NATIVE_LIB = "C:\path\to\nuvexa.dll"

4. Create, open, close

import { NuvexaDatabase } from "@nuventra/nuvexadb-node";

const path = "app.nvx";
const db = await NuvexaDatabase.create(path, key); // omit key / pass null for plaintext
await db.close();

if ((await NuvexaDatabase.isEncrypted(path)) && !key) {
  throw new Error("Encrypted .nvx — pass the key");
}
const opened = await NuvexaDatabase.open(path, key);
await opened.close();

5. Delete the database

import { unlink } from "node:fs/promises";

await db.close();
await unlink(path);
await unlink(path + "-wal").catch(() => {});

6. Collections

await db.insert("users", JSON.stringify({ name: "Ada", age: 36 }));
console.log(await db.listCollections());
await db.renameCollection("users", "people");
await db.dropCollection("people");

7. Documents

const id = await db.insert("users", JSON.stringify({ name: "Ada", age: 36 }));
await db.insertMany("users", JSON.stringify([{ name: "Grace", age: 85 }]));
const ada = await db.findById("users", id);
await db.replace("users", JSON.stringify({ _id: id, name: "Ada Lovelace", age: 36 }));
await db.deleteById("users", id);
const rows = await db.execute("db.users.find({ age: { $gte: 21 } }).limit(20)");

8. Password for an encrypted file

Read the key from the environment or a secret manager. Do not commit it. 1234 is a local demo only.

await db.changeEncryptionKey(currentKey, nextKey);

See Encryption notes.

Discussion

Comment on NuvexaDB. The thread lives on this component's GitHub repository (nuvyntralabs/NuvexaDB). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.