Skip to content

Node.js

Filesystem durability on Node.js 18+ with a destination adapter you supply.

Updated View as Markdown

The root package has no node: imports. On Node, import filesystem reliability from the subpath and supply a destination (TursoAdapter, ClickHouseAdapter, or a custom IAdapter). BunSQLiteAdapter will not load — it imports bun:sqlite.

audit.tsts
import { AuditLogger, ENTERPRISE_DEFAULTS, type IAdapter } from 'logbun';
import { FileReliabilityAdapter } from 'logbun/durability/filesystem';

declare const destination: IAdapter;

const instanceId = process.env.INSTANCE_ID ?? 'my-app-instance-1';

const audit = new AuditLogger({
  ...ENTERPRISE_DEFAULTS,
  namespace: 'my-app',
  reliability: new FileReliabilityAdapter({
    namespace: instanceId,
    dataDir: '.logbun',
    wal: { fsync: true },
    dlq: { fsync: true },
    encryptionKey: process.env.LOGBUN_ENCRYPTION_KEY,
  }),
  adapter: destination,
  redactPaths: ['password', 'token'],
  retention: { days: 90 },
});

await audit.ready;
await audit.fireAsync('user.created', {
  tenantId: 't1',
  actorId: 'u1',
});

Schedule runMaintenance() from cron or a supervisor. The filesystem adapter does not wake the process on its own.

encryptionKey accepts 32 raw bytes, 64-character hex, or base64 of 32 bytes. Passphrases are rejected (no silent SHA-256). See Production.

CJS require('logbun') and require('logbun/durability/filesystem') are supported. logbun/durability/cloudflare is ESM-only.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close