'Pass args groovy to Nodejs

I am trying to pass arguments from Groovy script pipeline to Nodejs in our project,

Some how, I am not able figure out where is the issue. Below is the code snippet.

Groovysample.groovy


argspass = "Test String";
script {
sh 'npm install'
sh 'node ./mynodescript.js ${argspass}'
}

Nodejs

const fs = require("fs");
const path = require("path");
let argValue = 0;
var htmlobj = '<html><h3> Testing the Node js command args </h3><table>';

callBack();

function callBack(){

process.argv.forEach((val, index) =>{
argValue = val;
htmlobj += '<tr>'+argValue+'</tr>'
});
htmlobj += '</table>'
htmlobj += '</body></html>';
const stream = fs.createWriteStream("./Test.html",{flags:"w"});
stream.write(htmlobj);
stream.close();
};



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source