Code
Overview
The Block Code is where you can write your custom code. It maximizes flexibility as you can write code to achieve things you can’t with the predefined block.
This block currently supports writing code in Typescript, you can also bring in your favorite npm packages by clicking on the fullscreen button and Add npm package*.
This is how the settings of this block will look when you add it to your flow:
Use cases
You can do almost anything you do with regular code. For example:
- Use a package to process a CSV file and parse it as a JSON array.
- Reformat output from previous steps to a different format expected by the following pieces.
- Filter outputs from previous steps by a custom criteria.
Instructions
You can configure the Code piece as follows:
Parameters
To use outputs from previous steps in your code, you have to pass them through the Parameters input.
Parameters are key/value pairs. The key you define here will become available in your code as a property of the argument in the main function. inputs
For example: In the image below we use message as the key and value as the output content of the previous step, you can access this parameter in your code.
The parameters become powerful when you pass outputs from previous steps.
Fullscreen
You can go to fullscreen to add npm packages and have a better coding and testing experience by clicking the fullscreen button.