Javascript Function
A summary of how to use the Javascript Function Node to execute code within a Flow.
Adding a Javascript Function Node

Overview

Buildable's Javascript Functions are built-in cloud functions that provide a powerful way to add custom synchronous logic to your Flows. You can use functions to transform or compute data, or even to perform more complex operations within Flows that you might otherwise need to write server-side code for. Buildable functions support Javascript (ES7) and provide access to select npm modules.
In a Javascript Function Node, you do not have access to perform requests to external API endpoints. To do this, you must use a Request Node.
If you know how to write Javascript, you'll know how to build a function in Buildable. In this section, we'll go over the following short concepts:

Defining input in a JavaScript Function Node

When you double click a function node, the code editor will open with 2 tabs. The focused tab is the input tab that allows you to select data that will be passed to your run function. Read more about selecting the input passed into the run function in the "What makes up a node?" section of the "Add Nodes to a Flow" page.

Writing code in a JavaScript Function Node

Navigate to the run function tab in the code editor to begin writing your code. You can write your custom code in the run function, which accepts any valid Javascript (ES7). The values defined in the input function would be passed as an object named input.
Below is an example function that adds 2 numbers, a and b.
Input
Run
Output
1
/**
2
* Lets you select the input for your node
3
*
4
* @param {Params} params
5
* @param {Object} $trigger - This flow's request object
6
* @param {Object} $nodes - Data from above nodes
7
*/
8
const nodeInput = ({ $trigger, $nodes }) => {
9
return {
10
a: 5,
11
b: 10
12
}
13
}
Copied!
1
/**
2
* @param {Run} input
3
*/
4
const run = (input) => {
5
return input.a + input.b; // Result will be 15
6
}
Copied!
1
15
Copied!
Functions can only be synchronous and do not have access to setTimeout, setInterval, setImmediate, queueMicrotask, and eval.

Using NPM Packages in a JavaScript Function Node

Buildable provides access to certain NPM modules that can be used within functions. Here's an example of how you can access the lodash NPM module within your run function.
1
const _ = require("lodash");
2
​
3
/**
4
* @param {Run} input
5
*/
6
const run = (input) => {
7
const adjectives = ["awesome", "inspiring", "astounding"];
8
​
9
const randomAdjective = _.sample(adjectives);
10
​
11
return `Buildable is ${randomAdjective}!`;
12
}
Copied!
Javascript Function Nodes do not have access to the axios and got npm packages.
You can see a full list of all the NPM packages in the Javascript Libraries Catalog. If you don't see the module that you're looking for, let us know and we can usually add it for you.

Throwing errors in a Javascript Function Node

If your function throws any form of error, whether syntax or otherwise, the error will be caught in the $nodeErrors object. You can read more about that in the Test a Flow page. You can throw errors as expected by using throw new Error().
Last modified 1mo ago