Skip to content

Code


Transform

Code is a widget flow node that allows you to execute custom JavaScript code.

Description

The Code node enables you to write and execute custom JavaScript code within your widget flow. This provides maximum flexibility for data processing, calculations, API integrations, or any other custom logic that can't be achieved with other nodes.

Configuration

Code

Code – the JavaScript code to execute. This node must export default a function - the code to execute. A function can be async if needed. You can write any valid JavaScript code, including:

  • Data manipulation and calculations;
  • API calls using fetch(), but we recommend http-request node;
  • DOM manipulation;
  • Complex business logic;
  • Accessing Browser APIs;
  • Custom functions and utilities.

Of course, we give you the ability to work with context values in a code node. To do this, you can use the ctx context object, which provides two methods: setValue and getValue.

For example:

js
/**
 * @param {CodeContextV1} ctx Widget flow context
 */
export default function(ctx) {
    const url = ctx.getValue('1.page_url'); // getting `1.page_url` context value

    ctx.addValue('url'); // setting X.url context value, where X is ID of code node
}

Limitations

NameValue
Max code length8192
InputsExactly one
OutputsExactly one

Context values