Type:
symbolA special value that can be passed as the env option of the Worker
constructor, to indicate that the current thread and the Worker thread should
share read and write access to the same set of environment variables.
import process from 'node:process'; import { Worker, SHARE_ENV } from 'node:worker_threads'; new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) .once('exit', () => { console.log(process.env.SET_IN_WORKER); // Prints 'foo'. });
const { Worker, SHARE_ENV } = require('node:worker_threads'); new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) .once('exit', () => { console.log(process.env.SET_IN_WORKER); // Prints 'foo'. });