Functions and libraries
Write a helper once and call it from every code block and run conditional of the flow, or import a JavaScript library such as crypto-js or dayjs.
Functions
Open Functions on the left. Whatever you define there can be called by name from every code block and run conditional in the flow. It is checked for syntax errors when you save.


// Money as text: money(12.5) → "$12.50"
function money(value) {
return "$" + Number(value).toFixed(2);
}
// Log in from anywhere and keep the token.
async function login(user, password) {
const r = await http({ method: "POST", url: $baseUrl + "/auth/login", body: { username: user, password } });
$token = JSON.parse(r.body).accessToken;
return r.status;
}
New flows start with the assertion helpers (assertStatus, assertJsonPath…), built on check(); change them or add your own. An older flow gets them with Insert assertion helpers. Checks in code.
Libraries
Functions → + Import library adds a JavaScript file to the flow. Its code is stored in the flow, so the flow and its export keep working on any machine. Each library shows as a badge above the functions: hover it to see how to use it, × removes it. Libraries load left to right, before your functions, so your functions can use them.
What works
- A single .js file. A plain script's functions are called directly:
toBase64(x). - A CommonJS file (
module.exports = …) or a UMD build of an npm package (usuallydist/*.min.jsor*.umd.js: crypto-js, dayjs, lodash…) is used through the name you give it, which CLEM suggests:CryptoJS.SHA256("abc"). - Not: ES modules (
import/export) and packages made of many files. Use their single-file build.
To update a library, import the new file under the same name.
// crypto-js.min.js imported as CryptoJS
const token = CryptoJS.AES.decrypt($cipher, $key).toString(CryptoJS.enc.Utf8);
log(CryptoJS.SHA256(token).toString());
// dayjs.min.js imported as dayjs
$tomorrow = dayjs().add(1, "day").format("YYYY-MM-DD");
Node built-ins
Many things need no library. require() offers these Node built-in modules, none of them for files or the network: assert, buffer, crypto, events, path, punycode, querystring, string_decoder, url, util and zlib.
const crypto = require("crypto");
$signature = crypto.createHmac("sha256", $apiSecret).update($payload).digest("hex");
// Base64 with Node alone
const encoded = Buffer.from("user:pass").toString("base64");
const decoded = Buffer.from(response.body, "base64").toString("utf8");