← All notes

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

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

Sources

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

Permanent ID: iil:note:gc2gg9nt

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.},
}

Markdown

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.