Node.js is a JavaScript runtime environment on Chrome V8 engine. JavaScript is a very common and used programming language from many programmers around the world. A variety of packages are offered for Node.js that provide different aspects of problem solving. The consideration of an integration scenario into an UiPath RPA workflow can only be profitable from these points of view.
It is possible to execute JavaScript code with Node.js or to use it in REPL (read-eval-print-loop) mode.
To realize a smart integration of Node.js with JavaScript into UiPath I have developed an activity. This activity works with compatibility modes Cross-platform (x64), Windows (x64) and Windows - Legacy (x86).
NodeJS.Activities.1.1.0.nupkg (20.6 KB)
With this it is possible to use JavaScript code via Node.js runtime environment easily.
To use this activity it is necessary to download Node.js and to install it on the target system first. Afterwards it is possible to set an environment variable NODE_HOME with the path to Node home directory. If the variable is not set it is necessary to set in the Options the NodeJSPath property to Node executable.
Here a tiny example which reads the input arguments and delivers it back.
//-Begin----------------------------------------------------------------
var myArgs = process.argv.slice(2);
if(typeof myArgs[0] == 'undefined') {
console.log("Hello World");
} else {
console.log("Hello " + myArgs[0]);
}
//-End------------------------------------------------------------------
The output is performed using the log method of the console class. This prints to stdout and is captured by the activity.
On this way we can seamlessly execute JavaScript source code in UiPath. For certain use cases this can be very advantageous.
JSON Returning
Very often in the JavaScript programming environment, results are returned in JavaScript Object Notation (JSON). This should be used without any problems.
//-Begin----------------------------------------------------------------
"use strict";
console.log(process.versions);
//-End------------------------------------------------------------------
To use this JSON return with UiPath.WebAPI.Activities it is necessary to convert the value to a JSON string in square brackets.
//-Begin----------------------------------------------------------------
"use strict";
console.log("[" + JSON.stringify(process.versions) + "]");
//-End------------------------------------------------------------------
Conclusion
Using Node.js with JavaScript opens further integration possibilities for UiPath, besides the possibility of using JavaScript as programming language. In particular, the using of network applications in the browser can be easily realized with it. This makes it very easy to implement local scenarios for test automation in this case. And all this in a very handy size.