Skip to main content

Introduction to Clients

Now that your Worker is running, it's time to start a Workflow Execution. You’ll need a Client to do this. A Client acts as the bridge for communication between your applications and the Temporal Service and performs actions such as:

  • Start a Workflow Execution
  • Cancel a Workflow Execution
  • Query a Workflow Execution
  • Get results from a Workflow Execution

We’ll use this code to start the reimbursement Workflow.

Client Code
import { Connection, Client } from '@temporalio/client';
import { reimbursementWorkflow } from './workflows';
async function run()
const connection = await Connection.connect({
address: 'localhost:7233' }); //Connect to the default Server location (localhost:7233)
const client = new Client({ connection });
const handle = await client.workflow.start(reimbursementWorkflow, {
args: ['User123', 100], //Arguments to be passed into reimbursementWorkflow
taskQueue: 'reimbursement-queue', // Tasks from reimbursementWorkflow are placed onto reimbursement-queue which is being polled by the Worker we configured
workflowId: 'reimbursement-workflow', // in practice, use a meaningful business ID, like customerId or transactionId
});
console.log(`Started workflow ${handle.workflowId}`);
const output = await handle.result();
console.log(output);
}
run().catch((err) => {
console.error(err);
process.exit(1);
});
5 / 10