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 🙏

© 2025 – Pkg Stats / Ryan Hefner

webworker-ng

v0.6.19

Published

The Web Worker implementation based on thread for Node.js

Downloads

63

Readme

node-webworker

Web Worker implementation for Node.js. This module provides multi-threads programming for Node.js user-land by borrowing the concept of the standard Web Worker.

Get Started

'use strict';
const WebWorker = require('webworker-ng').WebWorker;
const worker = new WebWorker((self) => {
  self.postMessage('foobar', {yorkie: true});
  self.on('message', (data) => {
    console.log(data);
  });
}, {
  timeout: 5000,  // terminate after timeout
  defines: [],    // the parameters/objects passing to Worker
});

worker.postMessage({foo: 'bar'});
worker.onmessage = function(data) {
  // get message from worker
};

APIs

The node-webworker provides the class WebWorker for creating a separate worker.

Creating a webworker script

A WebWorker instance is corresponding a script to run, in low-level implementation, it creates a thread to sperate the v8 stack from the main.

The constructor WebWorker(script, options) accepts:

  • {Function} script the source code function which runs in worker. Will support the path to run.
  • {Object} options the options to config the worker
    • {Number} options.timeout the microsecond number to terminate forcily.
    • {Array} options.define the array of parameters to pass in worker context.

Messaging

In host environment, namely the Node.js, every WebWorker instance owns the method postMessage and the listener onmessage.

worker.postMessage('some data');
worker.onmessage = function(data) {
  // TODO
};

Correspondingly, in every worker context, it owns the same like the following:

const worker = new WebWorker(function(self) {
  self.onmessage = function(data) { .. };
  self.postMessage('some data sent from worker');
});

Collecting stdout and stderr

In worker context, the methods under console as console.log() and console.error are delegated by node-webworker which allows user to collect worker logs by worker as the following:

const worker = new WebWorker(function(self) {
  console.log('this sent to stdout');
  console.error('this sent to stderr');
});
worker.onstdout = function(msg) { ... };
worker.onstderr = function(msg) { ... };

Modular worker

In web worker, you can use the following builtin modules:

  • events - the Node.js official events mirror module
  • path - the Node.js official path mirror module

The other hand, you can also load your CommonJS file into your worker:

const worker = new WebWorker(function(self) {
  require('./tests/load-worker.js');
});

Note: The default path routing is from the process.cwd().

Installation

$ npm install webworker-ng --save

Tests

$ npm test

License

Apache License 2.0