Can I launch a k6 process from inside of a node.js script using spawn or exec?

Hi, I am trying to start k6 process through spawn() or exec() from child_process module, as it is difficult to integrate k6 with node js framework. Something like below :
var spawn = require(‘child_process’).spawn;
spawn(‘k6’, [‘run’,‘loadTest.js’], { detached: false });
But this command doesn’t seem to run , do we have any work around for this ?


yes, this does work. See the NodeJS spawn() docs. You might be missing the stdout/stderr handlers.

Also, take a look at the --summary-export and --out json options, so you can avoid parsing the command output.

1 Like