Node.js worker_threads run CPU-heavy JavaScript in parallel and can share memory
Answer: The node:worker_threads module enables threads that execute JavaScript in parallel. Workers help with CPU-intensive JavaScript operations, but not much with I/O-intensive work, where the built-in asynchronous I/O operations are more efficient.
Minimal pattern
import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
if (isMainThread) {
const w = new Worker(new URL(import.meta.url), { workerData: { n: 40 } });
w.on('message', (r) => console.log(r));
w.on('error', console.error);
} else {
parentPort.postMessage(fib(workerData.n));
}
Facts
worker_threadscan share memory, unlikechild_processorcluster, by sharingSharedArrayBufferinstances or transferringArrayBufferinstances.SharedArrayBufferinstances in a posted value are accessible from either thread, and they cannot be listed intransferList.- A posted value may contain builtin JS types such as
RegExps,BigInts,Maps andSets, but not native (C++-backed) objects other than a short list such asMessagePortandKeyObject. - A
Workeremits'message','error','exit'and'online'events.
Why it matters
Node.js runs JavaScript code (initialization and callbacks) in the Event Loop, and a Worker Pool handles expensive tasks like file I/O.
See also
Claims
- id: C1 claim: Workers are useful for CPU-intensive JavaScript. source: S1 evidence: "Workers (threads) are useful for performing CPU-intensive JavaScript operations."
- id: C2 claim: Workers do not help much with I/O-intensive work. source: S1 evidence: "They do not help much with I/O-intensive work."
- id: C3 claim: worker_threads can share memory unlike child_process or cluster. source: S1 evidence: "Unlike child_process or cluster , worker_threads can share memory."
- id: C4 claim: Node runs JavaScript in the Event Loop and offers a Worker Pool. source: S2 evidence: "Node.js runs JavaScript code in the Event Loop"
Sources
- [S1] Worker threads. Node.js docs (API). https://nodejs.org/api/worker_threads.html . License: MIT. Accessed 2026-11-18.
- [S2] Don't Block the Event Loop (or the Worker Pool). Node.js docs (Learn). https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Worker threads; Node.js docs (Learn), Don't Block the Event Loop (or the Worker Pool). MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Worker threads; Node.js docs (Learn), Don't Block the Event Loop (or the Worker Pool). MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "Node.js worker_threads run CPU-heavy JavaScript in parallel and can share memory." iinventedlight Library, iil:note:gc2gg9nt, version of 2026-11-18. https://iinventedlight.com/library/notes/node-worker-threads/. License: CC-BY-4.0.
@misc{iil_note_gc2gg9nt,
author = {{iinventedlight}},
title = {{Node.js worker\_threads run CPU-heavy JavaScript in parallel and can share memory}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-worker-threads/},
note = {Permanent ID iil:note:gc2gg9nt. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-worker-threads.md.