How to create a Temporal Client in TypeScript
Use a new WorflowClient()
with the requisite gRPC Connection
to create a new Client.
import { Connection, WorkflowClient } from '@temporalio/client';
const connection = await Connection.connect(); // to configure for production
const client = new WorkflowClient({ connection });
Declaring the WorflowClient()
creates a new connection to the Temporal service.
If you omit the connection and just call the new WorkflowClient()
, you create a default connection that works locally.
However, always configure your connection and Namespace when deploying to production.
The following example, creates a Client, connects to an account, and declares your Namespace.
import { Connection, WorkflowClient } from '@temporalio/client';
const connection = await Connection.connect({
address: '<Namespace_ID>.tmprl.cloud',
});
const client = new WorkflowClient({
connection,
namespace: 'your.namespace',
});