node:worker_threads API Reference

Worker-thread and messaging compatibility surface

The namespace includes Worker, MessageChannel, MessagePort, BroadcastChannel, thread metadata, environment data, and transfer markers.

ExportPurpose
WorkerConstruct a worker from a file or evaluated source.
isMainThread, isInternalThread, threadIdIdentify the current thread.
parentPort, workerDataCommunicate with a parent worker.
MessageChannel, MessagePort, BroadcastChannelMessaging primitives.
getEnvironmentData(), setEnvironmentData()Worker environment data.
receiveMessageOnPort()Read a queued port message synchronously.
transfer-marker functionsControl cloning and transfer.
SHARE_ENV, resourceLimitsWorker configuration values.

Heap snapshots, port-to-context movement, and direct thread posting are not complete.

In 1.5, a new worker does not keep elide run alive. A standalone script can exit before worker event handlers run. Do not rely on Worker for standalone background work until lifecycle integration is complete.

For same-realm channels, see Web Messaging.

See also