PROCESIO
OverviewPlatform ActionsIntegrations & DemosCustom ActionsDeveloper’s Guide

Node

Th&x65;&x20;Node action is one of the actions at your disposal that allows you to execute Javascript code.

The Node action is one of the actions at your disposal that allows you to execute Javascript code.

Module imports can be performed using CommonJS require('module') syntax only.

Use the return keyword to set the output value. You can return either Single Values or List Values, not both at same time.

Timeout: → Integer representing execution time limit(when timeout limit is reached, the action will throw an error) Single result: → Output that will be set for single value outputs. List result: → Output that will be set for list value outputs. Error: → String representing errors resulted from the execution of the script (the output is set only when an error occurs, otherwise it’s null)

Something to consider before trying to use the Node action to automate your use cases is that it does not support working with files.

How to configure the Node action?

  1. Create a process and name it.
  2. Drag the Node action to the canvas and link it to the other actions.

3. Create the variables needed for the configuration of the action, and then add them to the configuration panel.

4. Add your Javascript Code to the editor.

5. Configure the output variables which will store the results.

6. Save, Validate and run.

7. Click Checked Instance to view the results. You will see that the outcome of the interpreted code is saved in the result variable. The script ran without errors so the value of the errorMessage variable is null.

Usage Examples:

1. Timeout:

return (async () => {     await new Promise(resolve => setTimeout(resolve, 10000)) //This code waits for 10 seconds. })()

Obs: If you set the Timeout to 5 seconds, the action will throw an error at runtime.

2. Scripts with Single outputs.

Integer

var a = 1 var b = 2 return a + b

Float

var a = 1.0 var b = 2.5 return a + b

String

var a = "aa" var b = "bb" return a + b

Boolean

var a = 1 var b = 2 return a == b

Json / DataModel

var x = { "user": { "id": 1, "name": "Someone", "height": 170.5 } }

return x

DateTime

let d = new Date() return d

Obs: These should only set the Single output. Should work for all types.

3. Scripts with List outputs.

let d = new Date(); let da = new Date();

return [d, da]

Obs: These should only set the List output. Should work for all types, just like single values. 4. Basic module usage

If the module does not support CommonJS require, we can’t use it

var _ = require('underscore');

return _.map([1, 2, 3], function(num){ return num * 3; })

const R = require('ramda');

const greet = R.replace('{name}', R.__, 'Hello, {name}!');

return greet('Alice');

let cheerio = require('cheerio') let $ = cheerio.load('<h2 class="title">Hello world</h2>')

$('h2.title').text('Hello there!') $('h2').addClass('welcome')

return $.html()

5. Syntax errors

var x = 1 retur x

Obs: Syntax errors will only set the Error field. 6. Throw behavior

var x = 1

throw "Not on my watch"

return x

Obs: Exception messages thrown using throw “message“ syntax will show up on the Error field. Only Error will be set after execution. 7. Async / Await

const axios = require('axios')

const findInDictionary = async (word) => &#123; const response = await axios.get(`https://api.dictionaryapi.dev/api/v2/entries/en/` + word) return response.data };

return findInDictionary('dog')

Available Node.js Libraries

The following libraries are available and can be used inside the Node.js Action:

Library
uuid
axios
cheerio
underscore
ramda
validator
lodash
xml
hash.js
html-to-json-parser
xml-js
moment
date-fns
marked
big.js
@faker-js/faker
joi
mathjs
csv-parse
papaparse
simple-statistics
luxon
string-similarity
qrcode

On this page