property workerId | Node.js node:test module | Bun {
// Worker ID is available via context
console.log(`Running in worker ${t.workerId}`);
// Or via environment variable (available at import time)
const workerId = process.env.NODE_TEST_WORKER_ID;
// Use workerId to allocate separate resources per worker
});
```"/> {
// Worker ID is available via context
console.log(`Running in worker ${t.workerId}`);
// Or via environment variable (available at import time)
const workerId = process.env.NODE_TEST_WORKER_ID;
// Use workerId to allocate separate resources per worker
});
```"/>
BuildDocsReferenceGuidesBlogDiscord/
node:test/
default/
TestContext/
workerIdPworkerId
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
node:test/
default/
TestContext/
workerIdPworkerId
property
test.default.TestContext.workerId {
// Worker ID is available via context
console.log(`Running in worker ${t.workerId}`);
// Or via environment variable (available at import time)
const workerId = process.env.NODE_TEST_WORKER_ID;
// Use workerId to allocate separate resources per worker
});
```" data-algolia-static="false" data-algolia-merged="false" data-type="Property">readonly
workerId: undefined | number
The unique identifier of the worker running the current test file. This value is derived from the NODE_TEST_WORKER_ID environment variable. When running tests with --test-isolation=process (the default), each test file runs in a separate child process and is assigned a worker ID from 1 to N, where N is the number of concurrent workers. When running with --test-isolation=none, all tests run in the same process and the worker ID is always 1. This value is undefined when not running in a test context.
This property is useful for splitting resources (like database connections or server ports) across concurrent test files:
import { test } from 'node:test';
import { process } from 'node:process';
test('database operations', async (t) => {
// Worker ID is available via context
console.log(`Running in worker ${t.workerId}`);
// Or via environment variable (available at import time)
const workerId = process.env.NODE_TEST_WORKER_ID;
// Use workerId to allocate separate resources per worker
});
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →