npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-shared-mem

v2.1.0

Published

High-performance native addon for mapping existing cross-process shared memory regions into Node.js

Downloads

517

Readme

node-shared-mem

npm version npm downloads License

High-performance Node.js native addon (napi) for mapping existing cross-process shared memory files. Handles V8 pointer compression and V8 Virtual Memory Cage compatibility transparently via automatic copy fallbacks.

Note: This module does not create shared memory blocks. Target memory regions must be allocated by an external process before initialization.

Features

  • Dual-Mode Compatibility: Uses zero-copy memory wrapping when possible, or explicit memory syncing when the V8 cage is active.
  • Cross-Platform: Supports Windows, Linux, and MacOS.

Installation & Compilation

Requires node-gyp, system build tools (g++, make, or Visual Studio Build Tools), and Python.

git clone https://github.com/aardvark-platform/node-shared-mem.git
cd node-shared-mem
npm install
npm run test
npm run test:electron

Usage

Because V8 sandbox configurations vary, you must check mem.requiresCopy to determine if manual memory synchronization is required.

Reading Data

const { SharedMemory, MemoryAccess } = require('node-shared-mem');

const mem = new SharedMemory("existing_shared_zone_name", 1024, MemoryAccess.READ); // Access permissions are optional, default is read and write
const buffer = mem.buffer; // Access the underlying ArrayBuffer
const view = new Uint8Array(buffer);

// Explicitly pull data from shared memory if required by V8 cage.
// This is a no-op if the V8 memory cage is disabled.
if (mem.requiresCopy) {
  mem.copyFrom();
}

console.log(view[0]);

Writing Data

const { SharedMemory } = require('node-shared-mem');

const mem = new SharedMemory("existing_shared_zone_name", 1024);
const buffer = mem.buffer;
const view = new Uint8Array(buffer);

view[0] = 42;

// Explicitly push data back to shared memory if required by V8 cage.
// This is a no-op if the V8 memory cage is disabled.
if (mem.requiresCopy) {
  mem.copyTo();
}

Subregion Copying (Partial Syncing)

Both copyFrom() and copyTo() accept three optional parameters to synchronize specific slices of memory rather than the entire buffer:

mem.copyFrom([srcOffset], [dstOffset], [length])
mem.copyTo([srcOffset], [dstOffset], [length])

// Example: Copy a 256-byte segment starting at byte 128
if (mem.requiresCopy) {
  const srcOffset = 128;
  const dstOffset = 128;
  const length = 256;
  
  mem.copyFrom(srcOffset, dstOffset, length);
}

Architecture: V8 Cage Constraints

V8 pointer compression mandates that all JavaScript ArrayBuffer backing stores reside within a single pre-allocated virtual memory sandbox (4GB–16GB). Raw memory pointers opened via OS hooks (shm_open or OpenFileMappingW) live outside this space and trigger fatal exceptions if wrapped directly inside a standard ArrayBuffer.

node-shared-mem resolves this internally:

  1. Cage Disabled: Wraps the shared memory pointer directly into mem.buffer (Zero-Copy mode). mem.requiresCopy resolves to false.
  2. Cage Enabled: Allocates mem.buffer inside the safe V8 cage. mem.requiresCopy resolves to true. The user must call mem.copyFrom() and mem.copyTo() to explicitly synchronize data between the V8 internal buffer and the external shared memory segment.

Publishing New Versions

Releases are automated via GitHub CI whenever a new semantic Git tag is pushed.

  1. Bump the version, commit, and tag atomically using npm version:

    # Options: patch, minor, or major
    npm version minor -m "chore: bump version to %s"
  2. Push the commit and the new tag to GitHub to trigger the release workflow:

    git push --tags

License

MIT