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-multithreaded

v1.0.2

Published

Enhances communication between the main thread and workers.

Readme

Multithreaded-Node Toolkit

A Node.js module providing tools to create high-performance, multithreaded applications.

Enhances communication between the main thread and workers using events and promises, utilizes shared memory for real-time updates, and much more.


Table of Contents


Installation

Install using the following command

npm install multithreaded-node

Features

  • No dependencies
  • Event-based communication between the main thread and the worker
  • Asynchronous request between the main thread and the worker
  • Shared memory between the main thread and the worker
  • Progress updates for heavy tasks
  • Worker state management

Getting Started

Below is a minimal structure to get you started with a main thread and a worker.

1. Using events

Set up a listener on the worker thread and emit events from the main thread.

📄 main.ts

import {startWorker} from "multithreaded-node"

const worker = await startWorker("./worker.ts")

// you can emit events
worker.emit("print", "Hello from the main thread!")

📄 worker.ts

import {initializeWorker} from "multithreaded-node"

const thread = initializeWorker()

// listen for events
thread.on('print', (msg) => {
    console.log(msg);
});

2. Using Promises

Send a request to the worker and receive a response using promises.

📄 main.ts

import {startWorker} from "multithreaded-node"

const worker = await startWorker("./worker.ts")

// request something async
worker.request("add", [1, 2]).then((result) => {
    console.log(result)
}).catch((err) => {
    console.error(err)
})

📄 worker.ts

import {initializeWorker} from "multithreaded-node"

const thread = initializeWorker()

// respond to requests
thread.respondTo('add', (array) => {
    return array.reduce((a, b) => a + b, 0);
});

3. Real-time statistics

Get the current CPU and memory usage of the worker.

📄 main.ts

import {startWorker} from "multithreaded-node"

const worker = await startWorker("./worker.ts")

console.log(worker.cpuUsage, "%")
console.log(worker.memorySnapshot)

📄 worker.ts

import {initializeWorker} from "multithreaded-node"

const thread = initializeWorker()

thread.trackMemory = true
thread.trackCpuUsage = true

Examples

Here’s a list of the examples included in this repository:

| Example | Description | |-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------| | 🔄 Main ↔ Worker Event Communication | Emit and capture events between the main thread and the worker | | 🔄 Main ↔ Worker Request/Response Communication | Send asynchronous request to the worker and receive a response using promises | | 🧪 Extend The Shared Memory | An example on how to use the SharedMemory and how to extend it | | 🧠 Heavy Task Handling with Worker | Handle heavy tasks with a busy state and progress updates |

Running Tests

You can run the test suite with:

npm test

License

This project is licensed under the MIT License.

Contributing

Pull requests and improvements are welcome! If you have additional worker-thread examples, feel free to submit a PR and expand the collection.

Notes

  • No external libraries are required — only Node.js built-in worker_threads is required.
  • Great for building advanced worker-based systems.
  • Works seamlessly with modern async/await syntax