before you read
It’s helpful to understand how to set up a project so you can start creating your own Durable Functions. In the next section, we’ll give you some guidance on how to do this from scratch.
However, since this course is designed for testers, you’re not required to set up your own project right now. In Lesson 3, you’ll be able to download an example project and observe how Durable Functions work in practice.
Still, knowing how to set up a Durable Function project from the beginning can give you a more complete understanding of how everything fits together.
1. The Function App Model in JavaScript
- An Azure Function App is a container for one or more individual functions.
- In JavaScript, you organize your function files under a single project directory, each with its own trigger and bindings configuration (
function.json
). - The function app manages runtime, configuration, and deployment as a single unit.
2. Activity, Orchestrator, and Client Functions Explained
-
Activity Functions:
- Single-purpose units of work (e.g., calling an API, reading/writing data).
- Can be executed independently and in parallel.
- Example: A function that resizes an image.
-
Orchestrator Functions:
- Define workflows using Durable Task Framework.
- Coordinate the calling of activity functions and manage control flow (loops, conditions, etc.).
- Example: An orchestrator that runs several activities in order or in parallel.
-
Client Functions:
- HTTP-triggered or otherwise externally triggered functions.
- Start new orchestrations and interact with running instances.
- Example: An HTTP endpoint to start a new order-processing workflow.
3. Creating Your First Durable Function in JavaScript
Step-by-step Example:
-
Install the Azure Functions Core Tools:
npm install -g azure-functions-core-tools@4 --unsafe-perm true
-
Create a New Function App:
func init MyDurableApp --javascript cd MyDurableApp
-
Install Durable Functions npm package:
npm install durable-functions
-
Create the Functions:
func new --template "Durable Functions orchestrator" --name MyOrchestrator func new --template "Durable Functions activity" --name MyActivity func new --template "HTTP trigger" --name HttpStart
note this can change, in vs code you have commands to create your project automatically
-
Update your code as needed and connect the orchestrator and activity in JavaScript.
4. Local Testing Basics with Azure Functions Core Tools
-
Run the Function App locally:
func start
-
Test your Durable Function:
- Trigger the
HttpStart
function using a tool like Postman or curl:curl -X POST http://localhost:7071/api/HttpStart
- Monitor logs and status output in your console.
- Trigger the
-
Debugging:
- Use your favorite JavaScript/TypeScript debugger (VS Code recommended).
- Set breakpoints and inspect local state.
Summary
- Durable Functions in JavaScript allow you to define complex, stateful workflows using activity, orchestrator, and client functions.
- The local development and testing experience is robust with the Azure Functions Core Tools.
- Start small: create a basic orchestrator, link activities, and explore workflow patterns!
Further Reading: