`node:worker_threads` runs JavaScript on a separate thread within the same process, each with its own event loop and V8 instance, communicating via message passing (or shared memory with `SharedArrayBuffer`).
js
// worker.js
import { parentPort, workerData } from "node:worker_threads";
parentPort.postMessage(workerData.n * workerData.n);
// main.js
import { Worker } from "node:worker_threads";
const w = new Worker("./worker.js", { workerData: { n: 7 } });
w.on("message", (result) => console.log(result)); // 49Unlike `child_process`, worker threads share memory more cheaply and start faster, making them the right tool for CPU-bound tasks like hashing large batches of data or heavy JSON parsing, without blocking the main thread's event loop.