← Back to documentation

Integrating with Existing Code

A core tenet of Flyde is that it should integrate with existing code, and not replace it.

To achieve this, Flyde provides a runtime library that allows you to load and run .flyde files, and a webpack loader that allows you to load .flyde files directly from your code. Also, custom nodes can be implemented using TypeScript or JavaScript (more on that in the custom nodes article).

For example, given a .flyde flow that converts Celsius to Fahrenheit:

Celsius to Fahrenheit flow

You can load and run it from your code as following:

import { runFlow } from "@flyde/loader";
import path from "path";

// Execute the flow directly with inputs
const result = await runFlow(path.join(__dirname, "celsius-to-fahrenheit.flyde"), {
  celsius: 0 // "celsius" is a main input in the flow
});

console.log(result.fahrenheit); // 32

The runFlow function directly returns the result of the flow execution.

For more advanced use cases, you can use the loadFlow function to get more control over execution:

import { loadFlow } from "@flyde/loader";

const execute = await loadFlow("./celsius-to-fahrenheit.flyde");
const { result } = execute(inputs, {
  onOutputs: (key, value) => {
    console.log(`output with key ${key} emitted value ${value}`);
  },
});

The example above assumes a Node.js environment. Loading Flyde in a browser environment is possible, but not yet documented. Checkout the website's source code, here and here for an example of how to do it.

:::note Learn more about the lifecycle of a flow in the advanced concepts article. :::

Another key method of intgrating with existing code is by creating your own custom nodes. Learn more about that in the custom nodes article.