An arbitrary JavaScript value that contains a clone of the data passed
to this thread's Worker constructor.
The data is cloned as if using postMessage(),
according to the HTML structured clone algorithm.
import { Worker, isMainThread, workerData } from 'node:worker_threads'; if (isMainThread) { const worker = new Worker(new URL(import.meta.url), { workerData: 'Hello, world!' }); } else { console.log(workerData); // Prints 'Hello, world!'. }
const { Worker, isMainThread, workerData } = require('node:worker_threads'); if (isMainThread) { const worker = new Worker(__filename, { workerData: 'Hello, world!' }); } else { console.log(workerData); // Prints 'Hello, world!'. }