
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
Server Web Workers for node.js that work.
This module is installed via npm:
$ npm install workerjs
Web Workers are part of the HTML 5 spec and:
defines an API that allows Web application authors to spawn background workers running scripts in parallel to their main page. This allows for thread-like operation with message-passing as the coordination mechanism
In effect, it allows you to get the benefit of multi-talking and multi-threading in single-threaded Javascript, as well as the safety of the event loop.
You can achieve this in node.js using the child_process.fork method, but then you have to use a different API.
This module normalizes the Web Worker API for server-side javascript in node.js with the hopes that we can build more multi-tasking modules built on the Web Worker standard that will work on both the server and the client-side using browserify.
By using Web Workers you can do CPU-intensive operations without blocking the event-loop and incoming IO:
// app.js - run with "node app.js"
var worker = new Worker('/path/to/fibworker.js');
worker.onmessage = function (msg) {
expect(msg.data).to.equal(1346269);
};
worker.postMessage(30);
// fibworker.js - CPU web worker code
self.onmessage = function (msg) {
self.postMessage(fibo(msg.data));
};
function fibo (n) {
return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}
I've also added a "node-friendly" option that allows the Web Worker to use
require() and other node.js conventions. To use this, just pass a boolean
value of true through to the second argument of the Worker contructor:
// app.js - run with "node app.js"
var worker = new Worker('/path/to/gammaworker.js', true);
worker.addEventListener('message', function (msg) {
expect(msg.data).to.equal(87178291200.00021);
done();
});
worker.postMessage(15);
// gammaworker.js - uses require
var gamma = require('gamma');
self.onmessage = function (msg) {
postMessage(gamma(msg.data));
};
Also, if you provide a module.exports function it will be executed as
an entry point of the web worker. This emulates the browserify transform
behaviour in webworkify:
// app.js - run with "node app.js"
var worker = new Worker('/path/to/gammaworker2.js', true);
worker.addEventListener('message', function (msg) {
expect(msg.data).to.equal(87178291200.00021);
done();
});
worker.postMessage(15);
// gammaworker2.js - uses require
var gamma = require('gamma');
module.exports = function () {
postMessage(gamma(msg.data));
};
FAQs
Server Web Workers for node.js that work
The npm package workerjs receives a total of 261 weekly downloads. As such, workerjs popularity was classified as not popular.
We found that workerjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.