I am trying to send the results of a SQL query to a NodeJS script for format manipulation. In this particular use case, I am converting the result set into an HTML table that I want to send back into an email task. I have the result set coming in from the query. I have the node script running and it returns data that I can see in the output. My issue is, the data does not seem to be piping into the script the way I assumed it would.
There is an exception: "Exception in Task: StandardIn has not been redirected."
This could be where my error is:
I am using the {TASK(PrevTask|StdOut)} in the StdIn field which may not be appropriate...
And my script is relatively simple:
var fs = require('fs');
let data = [];
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
var chunk;
while ((chunk = process.stdin.read()) !== null) {
data.push(chunk);
}
let table;
table += data.join('~');
//add styleing
table = `<style>td { border: solid 2px black;padding:0.25em;}</style>`;
table += `<table>`;
for (let i = 0; i < data.length; i++) {
let columns = data[i].split('~');
if (columns.length > 0) {
table += `<tr>`;
for (let k = 0; k < columns.length; k++) {
if (i == 0) {
table += '<th>' + columns[k] + '</th>';
} else {
if (isNaN(parseInt(columns[k]))) {
table += `<td style="${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
} else {
table += `<td style="text-align:center;${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
}
}
}
table += '</tr>';
}
}
table += '</table>';
fs.writeSync(1, table);
process.exit(0);
});