> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/run-workflow/javascript-typescript.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# JavaScript / TypeScript

Execute a workflow over HTTP and read `result`, `state`, and `executionId`.

## Complete example

```js
import { DNotifier } from "@dnotifier-realtime/dnotifier";
import { intentRouterWorkflow } from "./workflows/intent-router/workflow.js";

const USER_ID = "workflow-runner";

const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "http",
  userId: USER_ID,
  onConnected: () => console.log("Connected"),
  onMessage: () => {},
  onDisconnected: () => {},
});

await notifier.connect();

// Documentation-style question → search branch
const searchRun = await notifier.runWorkflow({
  workflow: intentRouterWorkflow,
  input: "How do refunds work?",
});

console.log("Branch:", searchRun.result?.branch);
console.log("Execution:", searchRun.executionId);

// General chat → general branch
const generalRun = await notifier.runWorkflow({
  workflow: intentRouterWorkflow,
  input: "What is your name?",
});

console.log("Branch:", generalRun.result?.branch);
console.log("Answer:", generalRun.result?.answer);
```

## Express API route

```js
app.post("/api/workflow/support", async (req, res) => {
  const { question } = req.body;

  const run = await notifier.runWorkflow({
    workflow: intentRouterWorkflow,
    input: question,
    senderId: req.user?.id ?? "anonymous",
  });

  res.json({
    result: run.result,
    executionId: run.executionId,
  });
});
```

## Blog pipeline input

```js
const run = await notifier.runWorkflow({
  workflow: blogArticleWorkflow,
  input: {
    topic: "Building AI workflows with DNotifier",
    keywords: ["workflow", "sdk", "observability"],
    audience: "developers",
    tone: "professional",
    wordCount: 900,
  },
});

console.log(run.result?.article?.slice(0, 200));
console.log(run.result?.seo?.metaTitle);
```

## Learn more

* [**Workflow observability**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/observability.md)
* [**Example: Multi-agent pipeline**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-multi-agent/javascript-typescript.md)
