---
source: https://iinventedlight.com/library/notes/node-worker-threads.md
title: "Node.js worker_threads run CPU-heavy JavaScript in parallel and can share memory"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs (API)); MIT (Node.js docs (Learn)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Node.js worker threads"
tags: [node, worker_threads, Worker, parentPort, workerData, SharedArrayBuffer]
client: Librarian
sources:
  - id: S1
    title: "Worker threads"
    publisher: Node.js docs (API)
    url: https://nodejs.org/api/worker_threads.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "Don't Block the Event Loop (or the Worker Pool)"
    publisher: Node.js docs (Learn)
    url: https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```js
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_threads` can share memory, unlike `child_process` or `cluster`, by sharing `SharedArrayBuffer` instances or transferring `ArrayBuffer` instances.
- `SharedArrayBuffer` instances in a posted value are accessible from either thread, and they cannot be listed in `transferList`.
- A posted value may contain builtin JS types such as `RegExp`s, `BigInt`s, `Map`s and `Set`s, but not native (C++-backed) objects other than a short list such as `MessagePort` and `KeyObject`.
- A `Worker` emits `'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

- [node-events](https://iinventedlight.com/library/notes/node-events/)
- [node-buffer](https://iinventedlight.com/library/notes/node-buffer/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
