Page History
...
- Node.js® is an open source, cross-platform JavaScript run-time environment and is a frequently used scripting language available for Linux, MacOS, Windows, and other platforms.
- This article explains how to include Node.js® scripts with JS7 job scripts- Shell Jobs. Use of Node.js® from the OS Shell is different from use of JS7 - JavaScript Jobs.
- As a prerequisite to executing Node.js® code it is required to install Node.js on the server for which the JS7 Agent is operated.
Invoking Node.js® from Shell Jobs
Unix
- Find the below examples for download (upload .json upload): run-Node.js-unix.workflow.json
In order to directly run Node.js® script code from a JS7 shell job script, the recommended approach is to use a shebang that runs Node.js® as the interpreter of the script like this:
Code Block language js title Example how run Node.js® script code with a shebang linenumbers true #!/usr/bin/node var name = (process.env.name); var num = parseInt(process.env.num); //print value of variable console.log( name); console.log( num);
Alternatively, the Node.js® script can be executed from a file that has to be is located within reach of the JS7 Agent that runs the job:
Code Block language js title Example how to run Node.js® script code from a file linenumbers true node /some/location/JS7-2.5.1/demosample_Node.js
Windows
- Find the below examples for download (.json upload): run-Node.js-windows.workflow.json
In order to directly run Node.js® script code from a JS7 shell job script, the recommended approach is to use a shebang that runs Node.js® as the interpreter of the script like this:
Code Block language js title Example how run PowerShell® Node.js® script code with a shebang replacement linenumbers true @@setlocal enabledelayedexpansion & @@findstr/v "^@@fv \"^@@[fs].*&\" \"%~f0\" | node.exe -&goto:eof & exit !errorlevel!/b& var name = (process.env.name); var num = parseInt(process.env.num); //print value of variable console.log( name); console.log( num);
Explanation:- If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes which are easily referenced from shell jobs, e.g. by using
##!include Node
//!include <name-of-script-include>
- The
node.exe
executable as available from the Node.js® installation is executed by the shebang.
- If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes which are easily referenced from shell jobs, e.g. by using
In addition, a Node.js® script can be executed from a file that has to be located with the JS7 Agent that runs implements the job:
Code Block language js title Example how to run Node.js® script code from a file linenumbers true node.exe C:\Users\Documents\demosample_Node.js
Passing Variables to subsequent Jobs
...
Download Example for Windows (.json upload): pdwVariablesPassingWindows.workflow.json
First Job:
...
Pass Return Variables
Shell jobs can pass results to subsequent jobs:
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#!/usr/bin/node const fs = require('fs'); // fetch the env.* variables var name = (process.env.name); var num = parseInt(process.env.num); // print value of variable console.log(name); console.log( num); //Modify modify the values var num1 = num + num; console.log( num1); var name1 = name + " This is JS7 "; console.log( name1); // pass results from a key/value pairpairs that isare appended to a temporary file provided by JS7 fs.appendFile(process.env.JS7_RETURN_VALUES, ,'num1=' + num1 + '\n', (err) => {}); fs.appendFile(process.env.JS7_RETURN_VALUES, ,'name1=' + name1 + '\n', (err) => {}); |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
@@setlocal enabledelayedexpansion & @@findstr/v \"^@@f^@@[fs].*&\" \"%~f0\" | node.exe -&goto:eof & exit !errorlevel!/b& const fs = require('fs'); // fetch the env.* variables var name = (process.env.name); var num = parseInt(process.env.num); // print value of variable console.log(name); console.log( num); //Modify modify the values var num1 = num + num; console.log( num1); var name1 = name + " This is JS7 "; console.log( name1); // pass results from a key/value pairpairs that isare appended to a temporary file provided by JS7 fs.appendFile(process.env.JS7_RETURN_VALUES, ,'num1=' + num1 + '\n', (err) => {}); fs.appendFile(process.env.JS7_RETURN_VALUES, ,'name1=' + name1 + '\n', (err) => {}); |
Second Job: Read Variables
...
- The JOC Cockpit GUI allows the mapping to be added per job from the right lower corner with the Environment Variables sub-tab.
- The mapping includes free choice of the name of an environment variable which is used in the job script and to assign an existing order variable.
- The spelling of variable names is case-sensitive.
The job script implementation looks like this:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#!/usr/bin/node var name1 = (process.env.name1); var num1 = parseInt(process.env.num1); // print value of variable console.log(name1); console.log( num1); |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
@@setlocal enabledelayedexpansion & @@findstr/v \"^@@f^@@[fs].*&\" \"%~f0\" | node.exe -&goto:eof & exit !errorlevel!/b& var name1 = (process.env.name1); var num1 = parseInt(process.env.num1); // print value of variable console.log(name1); console.log( num1); |