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

shared-space

v0.5.3

Published

Node.js shared object interface for cluster workers and thread workers

Readme

Shared objects for Node

This project aims to bring an easy to use interface for synchronising objects between worker threads or process forks.

Installation

npm install -s shared-space

This library requires node version > 12.x

Using with Node.js worker threads

// Main thread (main.js)
const { Worker } = require('worker_threads');
const path = require('path');
const { SharedObject } = require('shared-space');
const myObject = new SharedObject({
 initial: 'data'
});
for (let i=0; i < 4; i++) {
    let worker = new Worker(path.join(__dirname, 'worker.js'));
    myObject.shareWith(worker);
}
// Change any object field with
myObject.set('my.inner.key', 'someValue');   // => {my: {inner: {key: 'someValue'}}}
// Retrieve any object field with
console.log(myObject.get('my.inner.key'));
setTimeout(() => {
  console.log('Now we have', myObject.get('my.inner.key')); // prints 'worker'
}, 100);

// Worker thread (worker.js)
const { SharedObject } = require('shared-space');
const myObject = new SharedObject();
// Retrieve its data
console.log(myObject.get('initial'));   // prints 'data'
// Change data on all worker threads and main thread.
myObject.set('my.inner.key', 'worker');

Using with the Node.js cluster module

const cluster = require('cluster');
const { SharedObject } = require('shared-space');
if(cluster.isMaster) {
    // Initiate main shared object only in master process
    let myObject = new SharedObject({
        initial: 'data'
    });
    for (let i=0; i < 4; i++) {
        let child = cluster.fork();
        myObject.shareWith(child);
    }
    // Change any object field with
    myObject.set('my.inner.key', 'someValue');   // => {my: {inner: {key: 'someValue'}}}
    // Retrieve any object field with
    console.log(myObject.get('my.inner.key'));
    setTimeout(() => {
      console.log('Now we have', myObject.get('my.inner.key')); // prints 'worker'
    }, 100);

} else {
    // We are in a forked process
    let myObject = new SharedObject();
    console.log(myObject.get());  // prints the entire data object.
    myObject.set('some.field', 'value');  // propagates value to all forked children, and the main process
}

How it works

The library uses the standard Node cluster module (for when in cluster mode), or worker_threads (for when in thread mode). In essence, it performs object synchronisation between workers, by transferring object deltas (or changes) between workers, and merging the main data object.

Internally, when used with threads, it serializes the data using bson and sends/receives Uint8Array objects between workers. However, when used with the cluster module, it sends direct object JSONs between workers. Synchronisation is performed between all threads/processes (worker and main), with the last-update-wins scenario.

More examples are in the example folder

API

instance.constructor(initialData={})

Creates a new SharedObject instance and gives it the initial data.

instance.get(key?)

Returns the value of a specific key in the shared object. The key can use dot notation to retrieve inner objects (eg: my.inner.field) If no key is specified, the entire data object will be retrieved.

instance.set(key, value?)

Sets the given value to the specified key inside the object. The key uses dot notation, and overrides any value present in the object. If the key itself is an object, it will be merged with the shared object's data, overriding any values.

instance.clear(key)

Removes the specified key from the SharedObject's data. If no key is specified, the entire data object will be reset.

SharedSpace.SharedParent

The Shared object parent class used in main thread/process

SharedSpace.SharedChild

The Shared object child class used in sub-threads/processes

SharedSpace.SharedObject

either the SharedParent or the SharedChild, depending on the context of the process (parent/child)