In this tutorial we'll go over the different components that make up a Temporal project. All of the code in this page is included in our package initializer, set it up using the getting started instructions.
The SDK steers developers to write their Workflows and Activities in TypeScript but vanilla JS is also supported. All examples in the documentation are written in TypeScript.
Activities are called from Workflows in order to run non-deterministic code.
Activities are just async functions, they run like typical NodeJS code and can be cancelled and report heartbeats.
Workflows are the core of the Temporal system, they abstract away the complexities of writing distributed programs.
In the NodeJS SDK, each Workflow runs in a separate V8 isolate to provide a deterministic runtime.
A Workflow's interface is used for validating the implementation and generating a type safe WorkflowClient and
ChildWorkflow (not yet implemented).
Workflow interfaces are directly referenced by their implementation and may be written in sync or async form meaning a method could return
number or it could return
Workflow interface declarations are optional, they're only required for generating type safe clients. It is considered good practice to declare an interface for each Workflow.
A Workflow implmentation module may export a
workflow object which can be type checked using a pre-defined interface or
main - and optionally
queries - directly.
In a Workflow, Activities can be imported and called as regular functions. At runtime, the imported Activities (prefixed with
@activities) are replaced with stubs which schedule Activities in the system.
@activities is a typescript path alias set to
The Worker connects to the Service and runs Workflows and Activities.
Worker.create() accepts these options.
The client can be used to schedule Workflows and send other requests to the Temporal Service. It can be used in any NodeJS process e.g an express app and does not depend on the Worker.
There's no official support for testing Workflows and Activities.