Page History
...
- 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 can be invoked directly and can be parameterized like this:
Code Block language js title Example how run PowerShell® script code with a shebang replacement linenumbers true @@findstr/v "^@@f.*&" "%~f0"|node.exe -&goto:eof 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
- The Node.js®
node.exe
executable is available starting with node.js that can be used with the shebang accordingly.e.g. @@findstr/v "^@@f.*&" "%~f0"|node.exe -&goto:eof
- 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
Last but not least a Node.js® script can be executed from a file that has to be located by the executing Agent:
Code Block language js title Example how to run Node.js® script code from a file linenumbers true node.exe C:\Users\Documents\demo_Node.js
Implementation
Receiving Arguments
Arguments are provided by environment variables that are mapped to the job.
In the example the environment variable
name and num
is used.Returning Variables
Values can be returned as order return variables by writing
key=value
pairs to a temporary file that is provided by the Agent. There is one temporary file for each order in each workflow. The path to the temporary file is available from the environment variableJS7_RETURN_VALUES
. The return variable is available with the next instruction in the workflow.- Find the below examples for download (.json upload): run-powershell-unix.workflow.json
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/node
var name =(process.env.name);
var num = parseInt(process.env.num) ;
//print value of variable
console.log( name);
console.log( num);
console.log( "This is " +name+num ); |
Default Job Resource
A number of Arguments and Environment Variables can be provided from default Job Resources. These are available for download and can be assigned any workflows and jobs.
For download and explanations see JS7 - Job Environment Variables.