Quickstart | Get started with Resonate

Install the server and SDK and run your first Resonate workflow.

Resonate Quickstart banner

Install the server#

code
brew install resonatehq/tap/resonate

Install the SDK#

Requires Node.js 22 or later.

code
npm install @resonatehq/sdk

Write a function#

A countdown loop that survives restarts — minutes, hours, or days.

countdown.ts
import { Resonate, type Context } from "@resonatehq/sdk";

function* countdown(context: Context, count: number, delay: number) {
  for (let i = count; i > 0; i--) {
    // Run a function, persist its result
    yield* context.run((context: Context) => console.log(`Countdown: ${i}`));
    // Sleep
    yield* context.sleep(delay * 1000);
  }
  console.log("Done!");
}
// Instantiate Resonate
const resonate = new Resonate({ url: "http://localhost:8001" });
// Register the function
resonate.register(countdown);

Working example

Start the server#

code
resonate dev

Start the worker#

code
npx ts-node countdown.ts

Run the function#

Run the function with execution ID countdown.1:

code
resonate invoke countdown.1 --func countdown --arg 5 --arg 60

Result#

code
npx ts-node countdown.ts
Countdown: 5
Countdown: 4
Countdown: 3
Countdown: 2
Countdown: 1
Done!

What to try#

Inspect the execution with resonate tree — it renders the call graph as durable promises.

code
resonate tree countdown.1

Now kill the worker mid-countdown and restart. The countdown resumes where it stopped.

Next steps#