PROCESIO
OverviewPlatform ActionsIntegrations & DemosMarketplaceCustom ActionsDeveloper’s Guide

Node

Runs your own JavaScript code on Node.js inside a process and returns its result, its console output and any error.

The Node action runs a piece of JavaScript code that you write, on Node.js, as one step of your process. Use it for calculations, data clean-up or text processing that no ready-made action covers. The value your code returns becomes an output you can use in the next steps.

Add the action

In the Process Designer toolbox, open Scripting and pick Node (or type Node in the search box).

The Node action properties: Code, Timeout, Single Result, List Result, Stdout and Error

Inputs and outputs

FieldDirectionTypeRequiredWhat to put / what you get
CodeInputText (JavaScript code)YesYour JavaScript code. Use return to send a value back to the process.
TimeoutInputIntegerNoHow many seconds the code may run, from 10 to 180. Default 60.
Single ResultOutputAnyNoThe value your code returns, when it is not an array: a number, text, true/false or an object.
List ResultOutputList of anyNoThe value your code returns, when it is an array.
StdoutOutputTextNoEverything your code wrote with console.log().
ErrorOutputTextNoThe error message when your code fails or runs too long. Empty when the code worked.

How your code is run

Your code runs as the body of a function:

  • return <value> sends the value to Single Result, or to List Result when the value is an array. Only one of the two is filled.
  • console.log() does not set a result; it writes to Stdout.
  • Code that ends without return leaves both results empty.
  • To wait for something asynchronous, return a promise, for example an async function that you call: return (async () => { … })().
  • Load a library with require('name'). import statements are not supported.

Examples

CodeOutput
var a = 1; var b = 2; return a + bSingle Result 3
return 1 == 2Single Result false
console.log('working'); return [1, 'two', {three: 3}]List Result [1, "two", {"three": 3}], Stdout working
const _ = require('lodash'); return _.chunk([1,2,3,4], 2)List Result [[1, 2], [3, 4]]
throw "Not on my watch"Error Not on my watch
var x = 1 then retur x (a typo)Error Unexpected identifier 'x'
import _ from 'lodash'Error 'import' and 'export' may appear only with 'sourceType: module'
A promise that waits 15 seconds, with Timeout 10Error Execution timed out after 10s

Use process variables in the code

You can insert process variables into the code. Before the code runs, PROCESIO replaces each variable with its value, as plain text. So:

  • a number variable can be used as it is: const total = <your number variable> * 2;
  • a text variable needs quotes around it in your code: const name = "<your text variable>".

Good to know

  • A failing script does not stop the process. When your code throws, has a syntax error or runs longer than Timeout, the step still finishes: Error holds the message and both results are empty. Add a Decisional after the action that checks whether Error is empty.
  • The code runs in a sandbox. Built-in modules that reach the machine, such as fs or child_process, are not available, so the script cannot read or write files.
  • The sandbox can block calls to the internet. To call a web API, use Call API or CURL and pass the response to the script.
  • Files: a script cannot take a file directly. Convert the file to text with File To Base64 and pass the text to the script. To create a file from a script, return Base64 text and convert it with Base64 To File.

Available libraries

These libraries can be loaded with require:

LibraryWhat it is for
lodash, underscore, ramdaWorking with arrays and objects
moment, date-fns, luxonDates and times
big.js, mathjs, simple-statisticsPrecise numbers, maths and statistics
cheerio, html-to-json-parser, markedHTML and Markdown
xml, xml-jsXML
csv-parse, papaparseCSV
validator, joiValidating values
uuid, hash.js, qrcodeIDs, hashes, QR codes
string-similarityComparing texts
@faker-js/fakerRandom test data

On this page