Scripting
Node
11min
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 the list of currently allowed modules can be found below uuid https //www npmjs com/package/uuid https //www npmjs com/package/uuid axios https //www npmjs com/package/axios https //www npmjs com/package/axios cheerio https //www npmjs com/package/cheerio https //www npmjs com/package/cheerio underscore https //www npmjs com/package/underscore https //www npmjs com/package/underscore ramda https //www npmjs com/package/ramda https //www npmjs com/package/ramda validator https //www npmjs com/package/validator https //www npmjs com/package/validator lodash https //www npmjs com/package/lodash https //www npmjs com/package/lodash xml https //www npmjs com/package/xml https //www npmjs com/package/xml 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? create a process and name it 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 integer var a = 1 var b = 2 return a + b float float var a = 1 0 var b = 2 5 return a + b string string var a = "aa" var b = "bb" return a + b boolean boolean var a = 1 var b = 2 return a == b json / datamodel json / datamodel var x = { "user" { "id" 1, "name" "someone", "height" 170 5 } } return x datetime 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) => { const response = await axios get(`https //api dictionaryapi dev/api/v2/entries/en/` + word) return response data }; return findindictionary('dog')