Capturing console logs into a variable

Hi, I have this below yml script. My query is can I capture the logs of output of node app.js into some variable?? I would like to process the text.

image: node:latest
cache:
  paths:
    - node_modules/

test_async:
  script:
    - wget https://url/to/nodejs/script
    - npm install
    - node app.js

Hello, @vivekburman1 GM Socrates

Certainly! To capture the logs of the output of node app.js into a variable, you can override the console.log function to push messages to an array. Here’s how you can modify your script section:

test_async:
script:
- wget https:// url/to/nodejs/script
- npm install
- |
node -e "
var log = ;
console.log = function(d) {
log.push(d);
process.stdout.write(d + ‘\n’);
};
require(‘./app’);
// Now ‘log’ contains all the console output
// Process ‘log’ as needed
"

In the Node.js code, the console.log function is redefined to push each log message to the log array and also write it to the standard output. After running app.js, you can process the log array as needed.

Best Regard,
Ryan1969