Versions Compared

Key

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

...

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.

...

  • 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 , 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 bad another alternative the Node.js® executable can be invoked directly and can be parameterized like this, the Node.js® script can be executed from a file that has to be located by the executing Agent:

...

  • Find the below examples for download (.json upload)run-powershellNode.js-windows.workflow.json
  • In order to directly run Node.js® js® script code from a JS7 shell job script the recommended approach , the recommended approach is to use a shebang replacement 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:

    Credits for the shebang replacement to How to run a PowerShell script within a Windows batch file

      • 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 pwshNode
      • 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

  • 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



...