Skip to main content
The Node.js adapter uses napi-rs, which compiles a Rust crate into a .node native addon. The addon links directly to zinc-core and exposes a JavaScript class backed by the Rust core.

Installation

Requires Node.js 18 or later. The native addon is built for your platform at install time.

ZincRegion

create

Creates a new region. Throws if the name already exists or the size is invalid.

open

Opens an existing region. Throws if the region does not exist.

asBuffer

Returns a Node.js Buffer backed by the shared memory mapping. No copying occurs.
The buffer points directly into the mmap. Writing to the buffer modifies shared memory immediately.

notify

wait

Returns true if data was available, false on timeout.

Complete example

TypeScript

The package includes TypeScript declarations. The ZincRegion class and all its methods are fully typed.

napi-rs internals

The asBuffer method uses napi::Env::create_buffer_with_borrowed_data, which creates a Buffer from an externally-owned pointer without copying. The finalizer argument is a no-op because the mmap lifetime is managed by ZincRegion, not by the buffer’s garbage collection. The buffer must not be used after the region is closed.