Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Resources

Display children header

Links

Display content by label
Labelsjs7 api javascript
OtherTitleHow To ... JavaScript

Table of Contents

Introduction

  • Node.js® is an open-source, cross-platform JavaScript runtime environment and is a frequently used scripting language available for Linux, MacOS, Windows, and other platforms.
  • This article explains how to syntactically include Node.js® scripts with JS7 job scripts.
  • You want to Execute the Node.js code using the JS7 shell job script. First, you need to install Node.js on your server, where you are installing the Agent for Linux, MacOS, Windows, and other platforms.

Unix

  • Find the below examples for download (.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 can be invoked directly and can be parameterized like this:

    Code Block
    languagejs
    titleExample how run Node.js® script code with a shebang
    linenumberstrue
    #!/usr/bin/node
    
    var name =(process.env.name);
    var num = parseInt(process.env.num);
    
    //print value of variable   
    console.log( name);
    console.log( num);
  • As a another alternative, the Node.js® script can be executed from a file that has to be located by the executing Agent:
Code Block
languagejs
titleExample how to run Node.js® script code from a file
linenumberstrue
node  /home/{User}/JS7-2.5.1/demo_Node.js

Windows

...

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
languagejs
titleExample how run PowerShell® script code with a shebang replacement
linenumberstrue
@@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:

...

e.g. @@findstr/v "^@@f.*&" "%~f0"|node.exe -&goto:eof

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
languagejs
titleExample how to run Node.js® script code from a file
linenumberstrue
node.exe C:\Users\Documents\demo_Node.js

Implementation

Receiving Arguments

Arguments are provided by environment variables that are mapped to the job.

...

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 variable JS7_RETURN_VALUES. The return variable is available with the next instruction in the workflow.

...

Code Block
languagejs
titleReceiving Arguments and returning Variables
linenumberstrue
#!/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.

...