workflow
Version:
Workflow SDK - Build durable, resilient, and observable workflows
40 lines (27 loc) • 2.04 kB
text/mdx
---
title: createWorld
description: Create a new World instance from environment configuration.
type: reference
summary: Use createWorld to construct a fresh instance of the build-injected World, bypassing the cached instance.
prerequisites:
- /docs/api-reference/workflow-runtime/get-world
related:
- /docs/api-reference/workflow-runtime/set-world
---
Creates a new [World](/docs/api-reference/workflow-runtime/world) instance by invoking the World factory that was statically injected into the bundle at build time. The `WORKFLOW_TARGET_WORLD` environment variable selects the implementation, such as the local development World or the Vercel production World, when the app is built. Changing the variable at runtime has no effect.
Unlike [`getWorld()`](/docs/api-reference/workflow-runtime/get-world), which caches a singleton instance, `createWorld()` constructs a fresh instance on every call. Application code should almost always use `getWorld()`. `createWorld()` is for infrastructure code that manages World lifecycles itself.
```typescript lineNumbers
import { createWorld } from "workflow/runtime";
const world = await createWorld(); // [!code highlight]
```
This function does not accept any parameters. Configuration comes from the World that was injected at build time (World implementations typically read their own settings from environment variables when constructed).
### Returns
Returns a `Promise<World>` with a newly constructed World instance.
<Callout type="info">
Tooling that needs to construct a World with explicit (non-environment) configuration should instantiate the specific World implementation directly and register it with [`setWorld()`](/docs/api-reference/workflow-runtime/set-world).
</Callout>
## Related functions
- [`getWorld()`](/docs/api-reference/workflow-runtime/get-world): Resolve the cached World instance (preferred in application code).
- [`setWorld()`](/docs/api-reference/workflow-runtime/set-world): Override the cached World instance.